diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-12-22 13:32:50 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-12-22 13:32:50 -0200 |
commit | f84b575cfa52dc832751846aa0b4c8ff437d3ca3 (patch) | |
tree | 246ef484b08d132d006c16a6c8cbe55e61c3bfce /loadlib.c | |
parent | 3cb343efd644fb771b6d8193406afd49527dc1ec (diff) | |
download | lua-f84b575cfa52dc832751846aa0b4c8ff437d3ca3.tar.gz lua-f84b575cfa52dc832751846aa0b4c8ff437d3ca3.tar.bz2 lua-f84b575cfa52dc832751846aa0b4c8ff437d3ca3.zip |
no more pseudoindex LUA_GLOBALSINDEX; global table now accessible
through registry
Diffstat (limited to 'loadlib.c')
-rw-r--r-- | loadlib.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loadlib.c,v 1.69 2009/12/17 12:26:09 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.70 2009/12/17 13:06:47 roberto Exp roberto $ |
3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | ** | 5 | ** |
@@ -608,7 +608,8 @@ static int ll_module (lua_State *L) { | |||
608 | if (!lua_istable(L, -1)) { /* not found? */ | 608 | if (!lua_istable(L, -1)) { /* not found? */ |
609 | lua_pop(L, 1); /* remove previous result */ | 609 | lua_pop(L, 1); /* remove previous result */ |
610 | /* try global variable (and create one if it does not exist) */ | 610 | /* try global variable (and create one if it does not exist) */ |
611 | if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL) | 611 | lua_pushglobaltable(L); |
612 | if (luaL_findtable(L, 0, modname, 1) != NULL) | ||
612 | return luaL_error(L, "name conflict for module " LUA_QS, modname); | 613 | return luaL_error(L, "name conflict for module " LUA_QS, modname); |
613 | lua_pushvalue(L, -1); | 614 | lua_pushvalue(L, -1); |
614 | lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ | 615 | lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ |
@@ -635,7 +636,7 @@ static int ll_seeall (lua_State *L) { | |||
635 | lua_pushvalue(L, -1); | 636 | lua_pushvalue(L, -1); |
636 | lua_setmetatable(L, 1); | 637 | lua_setmetatable(L, 1); |
637 | } | 638 | } |
638 | lua_pushvalue(L, LUA_GLOBALSINDEX); | 639 | lua_pushglobaltable(L); |
639 | lua_setfield(L, -2, "__index"); /* mt.__index = _G */ | 640 | lua_setfield(L, -2, "__index"); /* mt.__index = _G */ |
640 | return 0; | 641 | return 0; |
641 | } | 642 | } |
@@ -713,7 +714,7 @@ LUAMOD_API int luaopen_package (lua_State *L) { | |||
713 | /* set field `preload' */ | 714 | /* set field `preload' */ |
714 | lua_newtable(L); | 715 | lua_newtable(L); |
715 | lua_setfield(L, -2, "preload"); | 716 | lua_setfield(L, -2, "preload"); |
716 | lua_pushvalue(L, LUA_GLOBALSINDEX); | 717 | lua_pushglobaltable(L); |
717 | luaL_register(L, NULL, ll_funcs); /* open lib into global table */ | 718 | luaL_register(L, NULL, ll_funcs); /* open lib into global table */ |
718 | lua_pop(L, 1); | 719 | lua_pop(L, 1); |
719 | return 1; /* return 'package' table */ | 720 | return 1; /* return 'package' table */ |