Replaced internal calls to luaL_register (deprecated in Lua 5.2) with an alternative

This commit is contained in:
Alex Szpakowski
2013-07-16 23:23:58 -03:00
parent 3725b4122f
commit 5a3055dd3b
5 changed files with 39 additions and 8 deletions
+22 -2
View File
@@ -198,6 +198,18 @@ int luax_assert_nilerror(lua_State *L, int idx)
return 0;
}
void luax_setfuncs(lua_State *L, const luaL_Reg *l)
{
if (l == 0)
return;
for (; l->name != 0; l++)
{
lua_pushcfunction(L, l->func);
lua_setfield(L, -2, l->name);
}
}
int luax_register_module(lua_State *L, const WrappedModule &m)
{
// Put a reference to the C++ module in Lua.
@@ -225,7 +237,8 @@ int luax_register_module(lua_State *L, const WrappedModule &m)
lua_newtable(L);
// Register all the functions.
luaL_register(L, 0, m.functions);
if (m.functions != 0)
luax_setfuncs(L, m.functions);
// Register types.
if (m.types != 0)
@@ -283,7 +296,7 @@ int luax_register_type(lua_State *L, const char *tname, const luaL_Reg *f)
lua_setfield(L, -2, "typeOf");
if (f != 0)
luaL_register(L, 0, f);
luax_setfuncs(L, f);
lua_pop(L, 1); // Pops metatable.
return 0;
@@ -323,6 +336,13 @@ int luax_register_searcher(lua_State *L, lua_CFunction f, int pos)
lua_getfield(L, -1, "loaders");
// Lua 5.2 renamed package.loaders to package.searchers.
if (lua_isnil(L, -1))
{
lua_pop(L, 1);
lua_getfield(L, -1, "searchers");
}
if (lua_isnil(L, -1))
return luaL_error(L, "Can't register searcher: package.loaders table does not exist.");