网站建设app,网站群建设工作,wordpress滑动文本框,网站建设实训总结200源码已经更新在CSDN的码库里#xff1a;
git clone https://gitcode.com/funsion/CLua.git在src文件夹下的lstrlib.c 标准字符串操作与模式匹配库函数#xff0c;表明这个C源文件实现了Lua的标准字符串操作与模式匹配库#xff0c;即提供了与字符串操作相关的API和功能实现…源码已经更新在CSDN的码库里
git clone https://gitcode.com/funsion/CLua.git在src文件夹下的lstrlib.c 标准字符串操作与模式匹配库函数表明这个C源文件实现了Lua的标准字符串操作与模式匹配库即提供了与字符串操作相关的API和功能实现。 增加中文版stringmetamethods 元方法列表保留英文版stringmetamethods元方法列表。 原始的代码为
static const luaL_Reg stringmetamethods[] {{__add, arith_add},{__sub, arith_sub},{__mul, arith_mul},{__mod, arith_mod},{__pow, arith_pow},{__div, arith_div},{__idiv, arith_idiv},{__unm, arith_unm},{__index, NULL}, /* placeholder */{NULL, NULL}
}; 更改成以下代码 /* 定义字符串的元方法列表 */
static const luaL_Reg stringmetamethods[] {{__add, arith_add},{__加,arith_add},{__sub, arith_sub},{__减,arith_sub},{__mul, arith_mul},{__乘,arith_mul},{__mod, arith_mod},{__取模,arith_mod},{__pow, arith_pow},{__乘方,arith_pow},{__div, arith_div},{__整除,arith_div},{__idiv, arith_idiv},{__向下整除, arith_idiv},{__unm, arith_unm},{__负号, NULL},{__index, NULL}, {__索引, NULL} ,/* 占位符 */{NULL, NULL}
};
原始的代码为 static const luaL_Reg strlib[] {{byte, str_byte},{char, str_char},{dump, str_dump},{find, str_find},{format, str_format},{gmatch, gmatch},{gsub, str_gsub},{len, str_len},{lower, str_lower},{match, str_match},{rep, str_rep},{reverse, str_reverse},{sub, str_sub},{upper, str_upper},{pack, str_pack},{packsize, str_packsize},{unpack, str_unpack},{NULL, NULL}
}; 更改成以下代码
/* strlib 结构体定义了字符串库中所有函数的映射关系 */
static const luaL_Reg strlib[] {{byte, str_byte}, /* byte函数用于提取字符串中的一个或多个字节 */{char, str_char}, /* char函数根据给定的数值创建一个字符串 */{dump, str_dump}, /* dump函数将函数转换为二进制字符串 */{find, str_find}, /* find函数在字符串中查找子字符串 */{format, str_format}, /* format函数根据指定的格式创建一个字符串 */{gmatch, gmatch}, /* gmatch函数返回一个迭代器用于在字符串中进行全局正则表达式匹配 */{gsub, str_gsub}, /* gsub函数在字符串中替换所有匹配的子串 */{len, str_len}, /* len函数返回字符串的长度 */{lower, str_lower}, /* lower函数将字符串中的大写字母转换为小写字母 */{match, str_match}, /* match函数在字符串中进行模式匹配 */{rep, str_rep}, /* rep函数重复字符串一定次数 */{reverse, str_reverse}, /* reverse函数反转字符串 */{sub, str_sub}, /* sub函数提取字符串的子串 */{upper, str_upper}, /* upper函数将字符串中的小写字母转换为大写字母 */{pack, str_pack}, /* pack函数将数据打包成二进制格式 */{packsize, str_packsize}, /* packsize函数返回给定格式数据打包后的大小 */{unpack, str_unpack}, /* unpack函数从二进制字符串中解包数据 */
/* 中文注释部分为对应的中文函数名便于中文用户理解 */{字节, str_byte},{字符, str_char},{转储, str_dump},{查找, str_find},{格式, str_format},{匹配, gmatch},{替换, str_gsub},{长度, str_len},{小写, str_lower},{配对, str_match},{重复, str_rep},{倒序, str_reverse},{子串, str_sub},{大写, str_upper},{打包, str_pack},{包尺寸, str_packsize},{拆包, str_unpack},{NULL, NULL} /* 结束标志 */
};
为了保证中英文 函数都可以加载以便你可以复制英文原码来进行更改。所以保留了英文版 函数名列表这样就能使用两种文的函数。 {byte, str_byte}, // 字节 {字节, str_byte}, // 和byte相同但是使用中文名称
其实它们都是加载同样的库名算是加载了2次以Lua内部算法应该只会加载一次。
更改完之后同样需要重新编译Lua的源码实现以上列出的关键词的中文化。
注意在Window系统下编译Lua, 最好将所有Lua的源码重新保存成ANSI格式的文件刚下载的默认的源码会是UTF-8格式的。
这个事情说三遍
1不然就会出现Window下的UTF-8源码可编译但Shell里的中文输出会乱码。 2要不然就是Window的ANSI源码不可编译假如你没做以上步骤 3如果是用ANSI格式的源码编译的Lua.exe对应的你在Window下写的Lua程序也是需要保存成ANSI格式的。这样就可以在Shell里输出正确的中文显示。