让石器的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;
          }
        }

1.png

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。