diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-10-23 17:12:19 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-10-23 17:12:19 -0200 |
commit | 5bc91c640588ca77b9f84146fc88fcc9bdbfbcd1 (patch) | |
tree | d5d049ad2357648cabe25c19a8620566e9f27131 /lbaselib.c | |
parent | f5073de0a72562e1998f23052715e56a3b9fde18 (diff) | |
download | lua-5bc91c640588ca77b9f84146fc88fcc9bdbfbcd1.tar.gz lua-5bc91c640588ca77b9f84146fc88fcc9bdbfbcd1.tar.bz2 lua-5bc91c640588ca77b9f84146fc88fcc9bdbfbcd1.zip |
no more one environment per thread: all threads share a single global
environment
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 13 |
1 files changed, 3 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.219 2009/10/05 16:44:33 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.220 2009/10/23 12:50:25 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -125,7 +125,7 @@ static void getfunc (lua_State *L, int opt) { | |||
125 | static int luaB_getfenv (lua_State *L) { | 125 | static int luaB_getfenv (lua_State *L) { |
126 | getfunc(L, 1); | 126 | getfunc(L, 1); |
127 | if (lua_iscfunction(L, -1)) /* is a C function? */ | 127 | if (lua_iscfunction(L, -1)) /* is a C function? */ |
128 | lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ | 128 | lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the global env. */ |
129 | else | 129 | else |
130 | lua_getfenv(L, -1); | 130 | lua_getfenv(L, -1); |
131 | return 1; | 131 | return 1; |
@@ -136,14 +136,7 @@ static int luaB_setfenv (lua_State *L) { | |||
136 | luaL_checktype(L, 2, LUA_TTABLE); | 136 | luaL_checktype(L, 2, LUA_TTABLE); |
137 | getfunc(L, 0); | 137 | getfunc(L, 0); |
138 | lua_pushvalue(L, 2); | 138 | lua_pushvalue(L, 2); |
139 | if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { | 139 | if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) |
140 | /* change environment of current thread */ | ||
141 | lua_pushthread(L); | ||
142 | lua_insert(L, -2); | ||
143 | lua_setfenv(L, -2); | ||
144 | return 0; | ||
145 | } | ||
146 | else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) | ||
147 | return luaL_error(L, | 140 | return luaL_error(L, |
148 | LUA_QL("setfenv") " cannot change environment of given object"); | 141 | LUA_QL("setfenv") " cannot change environment of given object"); |
149 | return 1; | 142 | return 1; |