让LUA支持中文变量 - 神奇石器时代技术研究交流
神奇石器技术研究交流网 - 业务联系QQ:420004208

让LUA支持中文变量

  • 内容
  • 相关

目前石器时代SF的服务端和客户端都用的是LUA5.1.4的引擎,但LUA并不支持中文变量,这里只需要稍微修改一下,即可让LUA支持中文变量,同时再把接口加入中文支持,完完全全可以像E语言那样进行LUA脚本编写,非常方便。同时可以让新手易学。

1、搜索下列代码:

        else if (isalpha(ls->current) || ls->current == '_') {
          /* identifier or reserved word */
          TString *ts;
          do {
            save_and_next(ls);
          } while (isalnum(ls->current) || ls->current == '_');
          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
                                  luaZ_bufflen(ls->buff));
          if (ts->tsv.reserved > 0)  /* reserved word? */
            return ts->tsv.reserved - 1 + FIRST_RESERVED;
          else {
            seminfo->ts = ts;
            return TK_NAME;
          }
        }

然后替换成下列代码即可

      else if (isalpha(ls->current) || ls->current == '_' || ls->current > 0x80) {
          /* identifier or reserved word */
          TString *ts;
          if (ls->current == 'L') {
            next(ls);
            if (ls->current == '"' || ls->current == '/') {
              read_wstring(ls, ls->current, seminfo);
              return TK_WSTRING;
            }
            save(ls, 'L');
          }
          /* identifier or reserved word */
          do {
              if(ls->current > 0x80)
              {
                 save_and_next(ls);
                 save_and_next(ls);
              }
              else
                 save_and_next(ls);
          } while (isalnum(ls->current) || ls->current == '_' || ls->current > 0x80);
          ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
                                  luaZ_bufflen(ls->buff));
          if (ts->tsv.reserved > 0)  /* reserved word? */
            return ts->tsv.reserved - 1 + FIRST_RESERVED;
          else {
            seminfo->ts = ts;
            return TK_NAME;
          }
        }
luachinese.png 

版权声明:若无特殊注明,本文皆为《sa60》原创,转载请保留文章出处。

本文链接:让LUA支持中文变量 - http://sa60.com/post-156.html

本文标签:

让LUA支持中文变量