aboutsummaryrefslogtreecommitdiff
path: root/linit.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-12-22 13:32:50 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2009-12-22 13:32:50 -0200
commitf84b575cfa52dc832751846aa0b4c8ff437d3ca3 (patch)
tree246ef484b08d132d006c16a6c8cbe55e61c3bfce /linit.c
parent3cb343efd644fb771b6d8193406afd49527dc1ec (diff)
downloadlua-f84b575cfa52dc832751846aa0b4c8ff437d3ca3.tar.gz
lua-f84b575cfa52dc832751846aa0b4c8ff437d3ca3.tar.bz2
lua-f84b575cfa52dc832751846aa0b4c8ff437d3ca3.zip
no more pseudoindex LUA_GLOBALSINDEX; global table now accessible
through registry
Diffstat (limited to 'linit.c')
-rw-r--r--linit.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/linit.c b/linit.c
index 264a4457..095a835a 100644
--- a/linit.c
+++ b/linit.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: linit.c,v 1.21 2009/12/11 13:40:44 roberto Exp roberto $ 2** $Id: linit.c,v 1.22 2009/12/17 12:26:09 roberto Exp roberto $
3** Initialization of libraries for lua.c and other clients 3** Initialization of libraries for lua.c and other clients
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -57,16 +57,19 @@ LUALIB_API void luaL_openlibs (lua_State *L) {
57 lua_call(L, 1, 0); 57 lua_call(L, 1, 0);
58 } 58 }
59 /* add open functions from 'preloadedlibs' into 'package.preload' table */ 59 /* add open functions from 'preloadedlibs' into 'package.preload' table */
60 luaL_findtable(L, LUA_GLOBALSINDEX, "package.preload", 0); 60 lua_pushglobaltable(L);
61 luaL_findtable(L, 0, "package.preload", 0);
61 for (lib = preloadedlibs; lib->func; lib++) { 62 for (lib = preloadedlibs; lib->func; lib++) {
62 lua_pushcfunction(L, lib->func); 63 lua_pushcfunction(L, lib->func);
63 lua_setfield(L, -2, lib->name); 64 lua_setfield(L, -2, lib->name);
64 } 65 }
65 lua_pop(L, 1); /* remove package.preload table */ 66 lua_pop(L, 1); /* remove package.preload table */
66#if defined(LUA_COMPAT_DEBUGLIB) 67#if defined(LUA_COMPAT_DEBUGLIB)
67 lua_getfield(L, LUA_GLOBALSINDEX, "require"); 68 lua_pushglobaltable(L);
69 lua_getfield(L, -1, "require");
68 lua_pushliteral(L, LUA_DBLIBNAME); 70 lua_pushliteral(L, LUA_DBLIBNAME);
69 lua_call(L, 1, 0); /* call 'require"debug"' */ 71 lua_call(L, 1, 0); /* call 'require"debug"' */
72 lua_pop(L, 1); /* remove global table */
70#endif 73#endif
71} 74}
72 75