aboutsummaryrefslogtreecommitdiff
path: root/lstate.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 /lstate.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 'lstate.c')
-rw-r--r--lstate.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/lstate.c b/lstate.c
index 1ea3e77f..2fc282e7 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.66 2009/12/16 16:42:58 roberto Exp roberto $ 2** $Id: lstate.c,v 2.67 2009/12/17 12:26:09 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -119,7 +119,8 @@ static int cpcall (lua_State *L) {
119 lua_CFunction f = *(lua_CFunction *)lua_touserdata(L, 1); 119 lua_CFunction f = *(lua_CFunction *)lua_touserdata(L, 1);
120 lua_remove(L, 1); /* remove f from stack */ 120 lua_remove(L, 1); /* remove f from stack */
121 /* restore original environment for 'cpcall' */ 121 /* restore original environment for 'cpcall' */
122 lua_copy(L, LUA_GLOBALSINDEX, LUA_ENVIRONINDEX); 122 lua_pushglobaltable(L);
123 lua_replace(L, LUA_ENVIRONINDEX);
123 return f(L); 124 return f(L);
124} 125}
125 126
@@ -138,10 +139,13 @@ static void init_registry (lua_State *L, global_State *g) {
138 setthvalue(L, &mt, L); 139 setthvalue(L, &mt, L);
139 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_MAINTHREAD), &mt); 140 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_MAINTHREAD), &mt);
140 /* registry[LUA_RIDX_CPCALL] = cpcall */ 141 /* registry[LUA_RIDX_CPCALL] = cpcall */
141 cp = luaF_newCclosure(L, 0, hvalue(&g->l_gt)); 142 cp = luaF_newCclosure(L, 0, g->l_gt);
142 cp->c.f = cpcall; 143 cp->c.f = cpcall;
143 setclvalue(L, &mt, cp); 144 setclvalue(L, &mt, cp);
144 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_CPCALL), &mt); 145 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_CPCALL), &mt);
146 /* registry[LUA_RIDX_GLOBALS] = l_gt */
147 sethvalue(L, &mt, g->l_gt);
148 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_GLOBALS), &mt);
145} 149}
146 150
147 151
@@ -152,7 +156,7 @@ static void f_luaopen (lua_State *L, void *ud) {
152 global_State *g = G(L); 156 global_State *g = G(L);
153 UNUSED(ud); 157 UNUSED(ud);
154 stack_init(L, L); /* init stack */ 158 stack_init(L, L); /* init stack */
155 sethvalue(L, &g->l_gt, luaH_new(L)); /* table of globals */ 159 g->l_gt = luaH_new(L); /* table of globals */
156 init_registry(L, g); 160 init_registry(L, g);
157 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ 161 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
158 luaT_init(L); 162 luaT_init(L);
@@ -253,7 +257,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
253 g->strt.nuse = 0; 257 g->strt.nuse = 0;
254 g->strt.hash = NULL; 258 g->strt.hash = NULL;
255 setnilvalue(&g->l_registry); 259 setnilvalue(&g->l_registry);
256 setnilvalue(&g->l_gt); 260 g->l_gt = NULL;
257 luaZ_initbuffer(L, &g->buff); 261 luaZ_initbuffer(L, &g->buff);
258 g->panic = NULL; 262 g->panic = NULL;
259 g->version = lua_version(NULL); 263 g->version = lua_version(NULL);