Lua中文语言编程源码-第六节,更改lmathlib.c 数学库函数, 使Lua加载中文库关键词(与数学库相关)

文章描述了一次对Lua源码中的mathlib数学库进行本地化修改的过程,增加了中文版函数名,同时指出在Windows系统下编译时需注意源码格式和字符编码问题,以避免中文显示乱码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

源码已经更新在CSDN的码库里:

git clone https://gitcode.com/funsion/CLua.git
在src文件夹下的lmathlib.c 数学库 函数,Standard mathematical library:表明这个C源文件实现了Lua的标准数学库(Standard mathematical library),即提供了与数学相关的API和功能实现。
增加中文版mathlib数学函数名列表,保留英文版mathlib数学函数名列表。
原始的代码为:
static const luaL_Reg mathlib[] = {
  {"abs",   math_abs},
  {"acos",  math_acos},
  {"asin",  math_asin},
  {"atan",  math_atan},
  {"ceil",  math_ceil},
  {"cos",   math_cos},
  {"deg",   math_deg},
  {"exp",   math_exp},
  {"tointeger", math_toint},
  {"floor", math_floor},
  {"fmod",   math_fmod},
  {"ult",   math_ult},
  {"log",   math_log},
  {"max",   math_max},
  {"min",   math_min},
  {"modf",   math_modf},
  {"rad",   math_rad},
  {"sin",   math_sin},
  {"sqrt",  math_sqrt},
  {"tan",   math_tan},
  {"type", math_type},
#if defined(LUA_COMPAT_MATHLIB)
  {"atan2", math_atan},
  {"cosh",   math_cosh},
  {"sinh",   math_sinh},
  {"tanh",   math_tanh},
  {"pow",   math_pow},
  {"frexp", math_frexp},
  {"ldexp", math_ldexp},
  {"log10", math_log10},
#endif
  /* placeholders */
  {"random", NULL},
  {"randomseed", NULL},
  {"pi", NULL},
  {"huge", NULL},
  {"maxinteger", NULL},
  {"mininteger", NULL},
  {NULL, NULL}
};
 更改成以下代码:
static const luaL_Reg mathlib[] = {
  {"abs",   math_abs},       {"绝对值", math_abs},
  {"acos",  math_acos},      {"反余弦", math_acos},
  {"asin",  math_asin},      {"反正弦", math_asin},
  {"atan",  math_atan},      {"反正切", math_atan},
  {"ceil",  math_c
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值