Portable way to replace standards Lua funcs

Signed-off-by: Arvydas Sidorenko <asido4@gmail.com>
This commit is contained in:
Arvydas Sidorenko 2012-06-08 01:25:35 +02:00 committed by Julien Danjou
parent d612b922f3
commit db0d23606d
1 changed files with 5 additions and 10 deletions

15
luaa.c
View File

@ -271,27 +271,22 @@ luaA_fixups(lua_State *L)
lua_setfield(L, -2, "wlen");
lua_pop(L, 1);
/* replace next */
lua_pushliteral(L, "next");
lua_pushcfunction(L, luaAe_next);
lua_settable(L, LUA_GLOBALSINDEX);
lua_setglobal(L, "next");
/* replace pairs */
lua_pushliteral(L, "pairs");
lua_pushcfunction(L, luaAe_next);
lua_pushcclosure(L, luaAe_pairs, 1); /* pairs get next as upvalue */
lua_settable(L, LUA_GLOBALSINDEX);
lua_setglobal(L, "pairs");
/* replace ipairs */
lua_pushliteral(L, "ipairs");
lua_pushcfunction(L, luaA_ipairs_aux);
lua_pushcclosure(L, luaAe_ipairs, 1);
lua_settable(L, LUA_GLOBALSINDEX);
lua_setglobal(L, "ipairs");
/* replace type */
lua_pushliteral(L, "type");
lua_pushcfunction(L, luaAe_type);
lua_settable(L, LUA_GLOBALSINDEX);
lua_setglobal(L, "type");
/* set selection */
lua_pushliteral(L, "selection");
lua_pushcfunction(L, luaA_selection_get);
lua_settable(L, LUA_GLOBALSINDEX);
lua_setglobal(L, "selection");
}
/** Look for an item: table, function, etc.