aboutsummaryrefslogtreecommitdiff
path: root/lapi.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 /lapi.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 'lapi.c')
-rw-r--r--lapi.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/lapi.c b/lapi.c
index 3b24d70c..2dee45a5 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.104 2009/12/15 11:25:36 roberto Exp roberto $ 2** $Id: lapi.c,v 2.105 2009/12/17 16:20:01 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -41,7 +41,7 @@ const char lua_ident[] =
41 41
42static Table *getcurrenv (lua_State *L) { 42static Table *getcurrenv (lua_State *L) {
43 if (L->ci->previous == NULL) /* no enclosing function? */ 43 if (L->ci->previous == NULL) /* no enclosing function? */
44 return hvalue(&G(L)->l_gt); /* use global table as environment */ 44 return G(L)->l_gt; /* use global table as environment */
45 else { 45 else {
46 Closure *func = curr_func(L); 46 Closure *func = curr_func(L);
47 return func->c.env; 47 return func->c.env;
@@ -67,10 +67,9 @@ static TValue *index2addr (lua_State *L, int idx) {
67 sethvalue(L, &L->env, getcurrenv(L)); 67 sethvalue(L, &L->env, getcurrenv(L));
68 return &L->env; 68 return &L->env;
69 } 69 }
70 case LUA_GLOBALSINDEX: return &G(L)->l_gt;
71 default: { 70 default: {
72 Closure *func = curr_func(L); 71 Closure *func = curr_func(L);
73 idx = LUA_GLOBALSINDEX - idx; 72 idx = LUA_ENVIRONINDEX - idx;
74 api_check(L, idx <= UCHAR_MAX + 1, "upvalue index too large"); 73 api_check(L, idx <= UCHAR_MAX + 1, "upvalue index too large");
75 return (idx <= func->c.nupvalues) 74 return (idx <= func->c.nupvalues)
76 ? &func->c.upvalue[idx-1] 75 ? &func->c.upvalue[idx-1]
@@ -204,11 +203,11 @@ static void moveto (lua_State *L, TValue *fr, int idx) {
204 } 203 }
205 else { 204 else {
206 setobj(L, to, fr); 205 setobj(L, to, fr);
207 if (idx < LUA_GLOBALSINDEX) /* function upvalue? */ 206 if (idx < LUA_ENVIRONINDEX) /* function upvalue? */
208 luaC_barrier(L, curr_func(L), fr); 207 luaC_barrier(L, curr_func(L), fr);
209 } 208 }
210 /* LUA_GLOBALSINDEX and LUA_REGISTRYINDEX do not need gc barrier 209 /* LUA_REGISTRYINDEX does not need gc barrier
211 (collector revisits them before finishing collection) */ 210 (collector revisits it before finishing collection) */
212} 211}
213 212
214 213