diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-03-29 14:43:14 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-03-29 14:43:14 -0300 |
commit | a8d3aa14fdcbc8c8ee6512bbcb4ad51a488a1e57 (patch) | |
tree | bda3a46753aff65cef00562e405b999c47fbb15b /lapi.c | |
parent | 064e406f67c0153999a5246deb1d616b06ee9bb0 (diff) | |
download | lua-a8d3aa14fdcbc8c8ee6512bbcb4ad51a488a1e57.tar.gz lua-a8d3aa14fdcbc8c8ee6512bbcb4ad51a488a1e57.tar.bz2 lua-a8d3aa14fdcbc8c8ee6512bbcb4ad51a488a1e57.zip |
global table now is only kept in the registry
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.116 2010/03/25 19:37:23 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.117 2010/03/26 20:58:11 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 | */ |
@@ -843,11 +843,17 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data, | |||
843 | if (!chunkname) chunkname = "?"; | 843 | if (!chunkname) chunkname = "?"; |
844 | luaZ_init(L, &z, reader, data); | 844 | luaZ_init(L, &z, reader, data); |
845 | status = luaD_protectedparser(L, &z, chunkname); | 845 | status = luaD_protectedparser(L, &z, chunkname); |
846 | if (status == LUA_OK) { | 846 | if (status == LUA_OK) { /* no errors? */ |
847 | Closure *f = clvalue(L->top - 1); | 847 | Closure *f = clvalue(L->top - 1); /* get newly created function */ |
848 | lua_assert(!f->c.isC); | 848 | lua_assert(!f->c.isC); |
849 | if (f->l.nupvalues == 1) | 849 | if (f->l.nupvalues == 1) { /* does it have one upvalue? */ |
850 | sethvalue(L, f->l.upvals[0]->v, G(L)->l_gt); | 850 | /* get global table from registry */ |
851 | Table *reg = hvalue(&G(L)->l_registry); | ||
852 | const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); | ||
853 | /* set global table as 1st upvalue of 'f' (may be _ENV) */ | ||
854 | setobj(L, f->l.upvals[0]->v, gt); | ||
855 | luaC_barrier(L, f, gt); | ||
856 | } | ||
851 | } | 857 | } |
852 | lua_unlock(L); | 858 | lua_unlock(L); |
853 | return status; | 859 | return status; |