no more pseudoindex LUA_GLOBALSINDEX; global table now accessible

through registry
This commit is contained in:
Roberto Ierusalimschy
2009-12-22 13:32:50 -02:00
parent 3cb343efd6
commit f84b575cfa
12 changed files with 63 additions and 53 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: linit.c,v 1.21 2009/12/11 13:40:44 roberto Exp roberto $
** $Id: linit.c,v 1.22 2009/12/17 12:26:09 roberto Exp roberto $
** Initialization of libraries for lua.c and other clients
** See Copyright Notice in lua.h
*/
@@ -57,16 +57,19 @@ LUALIB_API void luaL_openlibs (lua_State *L) {
lua_call(L, 1, 0);
}
/* add open functions from 'preloadedlibs' into 'package.preload' table */
luaL_findtable(L, LUA_GLOBALSINDEX, "package.preload", 0);
lua_pushglobaltable(L);
luaL_findtable(L, 0, "package.preload", 0);
for (lib = preloadedlibs; lib->func; lib++) {
lua_pushcfunction(L, lib->func);
lua_setfield(L, -2, lib->name);
}
lua_pop(L, 1); /* remove package.preload table */
#if defined(LUA_COMPAT_DEBUGLIB)
lua_getfield(L, LUA_GLOBALSINDEX, "require");
lua_pushglobaltable(L);
lua_getfield(L, -1, "require");
lua_pushliteral(L, LUA_DBLIBNAME);
lua_call(L, 1, 0); /* call 'require"debug"' */
lua_pop(L, 1); /* remove global table */
#endif
}