diff options
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 13 |
1 files changed, 6 insertions, 7 deletions
| @@ -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 | ||
| 42 | static Table *getcurrenv (lua_State *L) { | 42 | static 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 | ||
