Lua 5.2 Bata 版可在 http://www.lua.org/work/下载,下载地址是: http://www.lua.org/work/lua-5.2.0-beta.tar.gz。
Lua 5.2 中增加了goto语句。 要让Lua支持中文,可以通过以下的修改来实现,找到 llex.c 这个文件。找到static int llex (LexState *ls, SemInfo *seminfo)这个函数,以下代码是修改前的代码:
default: {
if (lislalpha(ls->current)) { /* identifier or reserved word? */
TString *ts;
do {
save_and_next(ls);
} while (lislalnum(ls->current));
ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
luaZ_bufflen(ls->buff));
seminfo->ts = ts;
if (ts->tsv.reserved > 0) /* reserved word? */
return ts->tsv.reserved - 1 + FIRST_RESERVED;
else {
return TK_NAME;
}
}
else { /* single-char tokens (+ - / ...) */
int c = ls->current;
next(ls);
return c;
}
}
}
}
}
下面这段代码是修改后的:
default: {
if (lislalpha(ls->current) || ls->current > 0x80) { /* identifier or reserved word? */
TString *ts;
do {
if(ls->current > 0x80)
{
save_and_next(ls);
save_and_next(ls);
}
else
save_and_next(ls);
}
while (lislalnum(ls->current) || ls->current > 0x80);
ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
luaZ_bufflen(ls->buff));
seminfo->ts = ts;
if (ts->tsv.reserved > 0) /* reserved word? */
return ts->tsv.reserved - 1 + FIRST_RESERVED;
else {
return TK_NAME;
}
}
else { /* single-char tokens (+ - / ...) */
int c = ls->current;
next(ls);
return c;
}
}
}
}
}
本文介绍了如何让Lua 5.2.0 Beta版本支持中文。通过修改llex.c文件中的static int llex (LexState *ls, SemInfo *seminfo)函数,增加对中文的支持。"
79754219,7489747,线性模型与高斯-马尔科夫定理解析,"['统计学', '机器学习', '线性回归']
691

被折叠的 条评论
为什么被折叠?



