本文章引用自 http://blog.csdn.net/chrisxie/archive/2008/09/29/2998290.aspx
但有所修正.
默认的LUA不支持中文变量名.
少量修改源代码即可
修改如下:
在lua\src\llex.c中 修改420行-432行内容
原内容
1 else if (isalpha(ls->current) || ls->current == '_') { 2 /* identifier or reserved word */ 3 TString *ts; 4 do { 5 save_and_next(ls); 6 } while (isalnum(ls->current) || ls->current == '_'); 7 ts = luaX_newstring(ls, luaZ_buffer(ls->buff), 8 luaZ_bufflen(ls->buff)); 9 if (ts->tsv.reserved > 0) /* reserved word? */ 10 return ts->tsv.reserved - 1 + FIRST_RESERVED; 11 else { 12 seminfo->ts = ts; 13 return TK_NAME; 14 } 15 } 16
修改为:
1 else if (isalpha(ls->current) || ls->current == '_' || ls->current > 0x80) { 2 /* identifier or reserved word */ 3 TString *ts; 4 do { 5 if(ls->current > 0x80) 6 { 7 save_and_next(ls); 8 save_and_next(ls); 9 } 10 else 11 save_and_next(ls); 12 } while (isalnum(ls->current) || ls->current == '_' || ls->current > 0x80); 13 ts = luaX_newstring(ls, luaZ_buffer(ls->buff), 14 luaZ_bufflen(ls->buff)); 15 if (ts->tsv.reserved > 0) /* reserved word? */ 16 return ts->tsv.reserved - 1 + FIRST_RESERVED; 17 else { 18 seminfo->ts = ts; 19 return TK_NAME; 20 } 21 } 22
注意我已经打过PATCH2了,可能和实际情况不大一样..不过,代码逻辑很容易,看下,应该也能明白
|
请发表评论