From 4664f2e9270a956f6175481abe590ba4931b7477 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 6 Aug 2002 15:54:18 -0300 Subject: any Lua closure has a table of globals (not only active functions) --- lapi.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'lapi.c') diff --git a/lapi.c b/lapi.c index 49ee0864..f66ec097 100644 --- a/lapi.c +++ b/lapi.c @@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 1.207 2002/08/06 15:32:22 roberto Exp roberto $ +** $Id: lapi.c,v 1.208 2002/08/06 17:06:56 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -506,24 +506,11 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) { } -static LClosure *getfunc (lua_State *L, int level) { - CallInfo *ci; - TObject *f; - if (L->ci - L->base_ci < level) ci = L->base_ci; - else ci = L->ci - level; - f = ci->base - 1; - if (isLfunction(f)) - return &clvalue(f)->l; - else - return NULL; -} - - -LUA_API void lua_getglobals (lua_State *L, int level) { - LClosure *f; +LUA_API void lua_getglobals (lua_State *L, int index) { + StkId o; lua_lock(L); - f = getfunc(L, level); - setobj(L->top, (f ? &f->g : gt(L))); + o = luaA_index(L, index); + setobj(L->top, isLfunction(o) ? &clvalue(o)->l.g : gt(L)); api_incr_top(L); lua_unlock(L); } @@ -608,16 +595,20 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) { } -LUA_API int lua_setglobals (lua_State *L, int level) { - LClosure *f; +LUA_API int lua_setglobals (lua_State *L, int index) { + StkId o; + int res = 0; lua_lock(L); api_checknelems(L, 1); - f = getfunc(L, level); + o = luaA_index(L, index); L->top--; api_check(L, ttistable(L->top)); - if (f) f->g = *(L->top); + if (isLfunction(o)) { + res = 1; + clvalue(o)->l.g = *(L->top); + } lua_unlock(L); - return (f != NULL); + return res; } -- cgit v1.2.3-55-g6feb