lua 5.1 ==> 5.2

============》第一条:

默认情况下,lua5.2中没有 【luaL _openlib】api了,这是5.1中的API,实现于【lauxlib.c】中。至于替代方案,可以是这样:

luaL_openlib(L, "mylib", mylib, 0)
变成
//Pushes onto the stack the value of the global name.
lua_getglobal(L, "mylib");
if (lua_isnil(L, -1)) {
  lua_pop(L, 1);
  lua_newtable(L);
}
//Registers all functions in the array l (see luaL_Reg) into the table on the top of the stack
luaL_setfuncs(L, mylib, 0);
 
Pops a value from the stack and sets it as the new value of global name.
lua_setglobal(L, "mylib");

============》第二条

lua5.2中【luaL_register】已经废弃了,因为会污染全局名字。以下是lua5.2官方文档的说明: 

  • Function luaL_register is deprecated. Use luaL_setfuncs so that your module does not create globals. (Modules are not expected to set global variables anymore.)

一般建议这样子写:

lua_newtable(L);
luaL_setfuncs(L, mylib, 0);
return 1;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值