从零开始

 找回密码
 立即注册

QQ登录

只需一步,快速开始

微信登录

微信扫码,快速开始

搜索
热搜: C++
查看: 2146|回复: 1

修改lua源文件,让lua支持中文函数

[复制链接]
  • TA的每日心情

    2019-9-14 20:01
  • 签到天数: 12 天

    [LV.3]偶尔看看II

    6

    主题

    14

    帖子

    1741

    积分

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    1741
    发表于 2019-1-16 14:33:55 | 显示全部楼层 |阅读模式
    方法一.

    /*中文支持
    llex.c
    static int llex (LexState *ls, SemInfo *seminfo)
    修改如下:
    */
          default: {
            if (lislalpha(ls->current) || 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 == '_' || ls->current > 0x80);
              ts = luaX_newstring(ls, luaZ_buffer(ls->buff),
                                      luaZ_bufflen(ls->buff));
              seminfo->ts = ts;
              if (isreserved(ts))  /* reserved word? */
                return ts->extra - 1 + FIRST_RESERVED;
              else {
                return TK_NAME;
              }
            }
            else {  /* single-char tokens (+ - / ...) */
              int c = ls->current;
              next(ls);
              return c;
            }
          }
    /*-----------------------------------------------------------------------------*/
    /*源代码*/   
        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 (isreserved(ts))  /* reserved word? */
                return ts->extra - 1 + FIRST_RESERVED;
              else {
                return TK_NAME;
              }
            }
            else {  /* single-char tokens (+ - / ...) */
              int c = ls->current;
              next(ls);
              return c;
            }
          }
    方法二.

    /* lctype.c *
    /把8至B行和E行全部修改为0x01或者0x05可以让 Lua 认为汉字是可打印的)

    /*
    ** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $
    ** 'ctype' functions for Lua
    ** See Copyright Notice in lua.h
    */

    #define lctype_c
    #define LUA_CORE

    #include "lprefix.h"


    #include "lctype.h"

    #if !LUA_USE_CTYPE    /* { */

    #include

    LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {
      0x00,  /* EOZ */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* 0. */
      0x00,  0x08,  0x08,  0x08,  0x08,  0x08,  0x00,  0x00,
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* 1. */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
      0x0c,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,    /* 2. */
      0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,
      0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,    /* 3. */
      0x16,  0x16,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,
      0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,    /* 4. */
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,    /* 5. */
      0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x05,
      0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,    /* 6. */
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,    /* 7. */
      0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x00,
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,    /* 8. */
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,    /* 9. */
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,    /* a. */
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,    /* b. */
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* c. */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* d. */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,    /* e. */
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* f. */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
    };

    #endif            /* } */

    /*源代码*/
    /*
    ** $Id: lctype.c,v 1.12 2014/11/02 19:19:04 roberto Exp $
    ** 'ctype' functions for Lua
    ** See Copyright Notice in lua.h
    */

    #define lctype_c
    #define LUA_CORE

    #include "lprefix.h"


    #include "lctype.h"

    #if !LUA_USE_CTYPE    /* { */

    #include

    LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {
      0x00,  /* EOZ */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* 0. */
      0x00,  0x08,  0x08,  0x08,  0x08,  0x08,  0x00,  0x00,
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* 1. */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
      0x0c,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,    /* 2. */
      0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,
      0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,  0x16,    /* 3. */
      0x16,  0x16,  0x04,  0x04,  0x04,  0x04,  0x04,  0x04,
      0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,    /* 4. */
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,    /* 5. */
      0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x05,
      0x04,  0x15,  0x15,  0x15,  0x15,  0x15,  0x15,  0x05,    /* 6. */
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,
      0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,  0x05,    /* 7. */
      0x05,  0x05,  0x05,  0x04,  0x04,  0x04,  0x04,  0x00,
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* 8. */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* 9. */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* a. */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* b. */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* c. */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* d. */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* e. */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,    /* f. */
      0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,  0x00,
    };

    #endif            /* } */
    回复

    使用道具 举报

  • TA的每日心情
    无聊
    5 天前
  • 签到天数: 147 天

    [LV.7]常住居民III

    172

    主题

    473

    帖子

    36万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    360285
    QQ
    发表于 2019-1-19 11:35:11 | 显示全部楼层
    支持
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|小黑屋|手机版|Archiver|一切从零开始 ( 蜀ICP备15031375号-3 )

    GMT+8, 2024-5-19 09:12 , Processed in 0.184861 second(s), 10 queries , File On.

    Powered by Discuz! X3.4

    © 2001-2017 Comsenz Inc.

    快速回复 返回顶部 返回列表