Lua 5.3.5
总共需要修改3个文件
lctype.c一大串数组定义改为
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, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, /* a. */
0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, /* b. */
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, /* c. */
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, /* d. */
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, /* e. */
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64,
0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, /* f. */
0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00
lctype.h
#include <limits.h>
#include "llimits.h"
#define ALPHABIT 0
#define DIGITBIT 1
#define PRINTBIT 2
#define SPACEBIT 3
#define XDIGITBIT 4
#define GBLBIT 5 //GB2312低位
#define GBHBIT 6 //GB2312高位
#define MASK(B) (1 << (B))
#define testprop(c,p) (luai_ctype_[(c)+1] & (p))
#define lislalpha(c) testprop(c, (MASK(ALPHABIT)|MASK(GBHBIT))) //添加 高位判断
#define lislalnum(c) testprop(c, (MASK(ALPHABIT)|MASK(DIGITBIT)|MASK(GBHBIT))) //添加 高位判断
#define lisdigit(c) testprop(c, MASK(DIGITBIT))
#define lisspace(c) testprop(c, MASK(SPACEBIT))
#define lisprint(c) testprop(c, MASK(PRINTBIT))
#define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
#define lisgbl(c) testprop(c, MASK(GBLBIT)) //GB2312低位判断
#define lisgbh(c) testprop(c, MASK(GBHBIT)) //GB2312高位判断
#define ltolower(c) ((c) | ('A' ^ 'a'))
LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2];
llex.c中llex函数的default中的do..while循环改为:
do {
if(lisgbh(ls->current)) //添加此判断
{
save_and_next(ls);
if(!lisgbl(ls->current)) break;
}
save_and_next(ls);
} while (lislalnum(ls->current));
这样Lua就可以支持完整的GB2312中文字符,不会包含特殊符号和繁体字。