diff options
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 29 |
1 files changed, 12 insertions, 17 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.157 2001/10/25 19:14:14 roberto Exp $ | 2 | ** $Id: lapi.c,v 1.158 2001/10/31 19:40:14 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 | */ |
@@ -44,13 +44,16 @@ static TObject *negindex (lua_State *L, int index) { | |||
44 | if (index > LUA_REGISTRYINDEX) { | 44 | if (index > LUA_REGISTRYINDEX) { |
45 | api_check(L, index != 0 && -index <= L->top - L->ci->base); | 45 | api_check(L, index != 0 && -index <= L->top - L->ci->base); |
46 | return L->top+index; | 46 | return L->top+index; |
47 | } else if (index == LUA_REGISTRYINDEX) /* pseudo-indices */ | 47 | } |
48 | return &G(L)->registry; | 48 | else switch (index) { /* pseudo-indices */ |
49 | else { | 49 | case LUA_REGISTRYINDEX: return &G(L)->registry; |
50 | TObject *func = (L->ci->base - 1); | 50 | case LUA_GLOBALSINDEX: return &L->gt; |
51 | index = LUA_REGISTRYINDEX - index; | 51 | default: { |
52 | api_check(L, iscfunction(func) && index <= clvalue(func)->c.nupvalues); | 52 | TObject *func = (L->ci->base - 1); |
53 | return &clvalue(func)->c.upvalue[index-1]; | 53 | index = LUA_GLOBALSINDEX - index; |
54 | api_check(L, iscfunction(func) && index <= clvalue(func)->c.nupvalues); | ||
55 | return &clvalue(func)->c.upvalue[index-1]; | ||
56 | } | ||
54 | } | 57 | } |
55 | } | 58 | } |
56 | 59 | ||
@@ -381,14 +384,6 @@ LUA_API void lua_rawgeti (lua_State *L, int index, int n) { | |||
381 | } | 384 | } |
382 | 385 | ||
383 | 386 | ||
384 | LUA_API void lua_getglobals (lua_State *L) { | ||
385 | lua_lock(L); | ||
386 | sethvalue(L->top, L->gt); | ||
387 | api_incr_top(L); | ||
388 | lua_unlock(L); | ||
389 | } | ||
390 | |||
391 | |||
392 | LUA_API void lua_newtable (lua_State *L) { | 387 | LUA_API void lua_newtable (lua_State *L) { |
393 | lua_lock(L); | 388 | lua_lock(L); |
394 | sethvalue(L->top, luaH_new(L, 0, 0)); | 389 | sethvalue(L->top, luaH_new(L, 0, 0)); |
@@ -453,7 +448,7 @@ LUA_API void lua_setglobals (lua_State *L) { | |||
453 | api_checknelems(L, 1); | 448 | api_checknelems(L, 1); |
454 | newtable = --L->top; | 449 | newtable = --L->top; |
455 | api_check(L, ttype(newtable) == LUA_TTABLE); | 450 | api_check(L, ttype(newtable) == LUA_TTABLE); |
456 | L->gt = hvalue(newtable); | 451 | setobj(&L->gt, newtable); |
457 | lua_unlock(L); | 452 | lua_unlock(L); |
458 | } | 453 | } |
459 | 454 | ||