============》第一条:
默认情况下,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 arrayl
(seeluaL_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. UseluaL_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;