lua 5.1 ==> 5.2

来源:互联网 发布:苹果mac使用 编辑:程序博客网 时间:2024/06/05 21:00

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

默认情况下,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 stackluaL_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;


0 0
原创粉丝点击