diff options
| -rw-r--r-- | lbaselib.c | 9 |
1 files changed, 6 insertions, 3 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.177 2005/05/20 15:53:42 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.178 2005/05/25 13:21:26 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 | */ |
| @@ -133,7 +133,7 @@ static void getfunc (lua_State *L) { | |||
| 133 | static int luaB_getfenv (lua_State *L) { | 133 | static int luaB_getfenv (lua_State *L) { |
| 134 | getfunc(L); | 134 | getfunc(L); |
| 135 | if (lua_iscfunction(L, -1)) /* is a C function? */ | 135 | if (lua_iscfunction(L, -1)) /* is a C function? */ |
| 136 | lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the global env. */ | 136 | lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ |
| 137 | else | 137 | else |
| 138 | lua_getfenv(L, -1); | 138 | lua_getfenv(L, -1); |
| 139 | return 1; | 139 | return 1; |
| @@ -145,7 +145,10 @@ static int luaB_setfenv (lua_State *L) { | |||
| 145 | getfunc(L); | 145 | getfunc(L); |
| 146 | lua_pushvalue(L, 2); | 146 | lua_pushvalue(L, 2); |
| 147 | if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { | 147 | if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { |
| 148 | lua_replace(L, LUA_GLOBALSINDEX); | 148 | /* change environment of current thread */ |
| 149 | lua_pushthread(L); | ||
| 150 | lua_insert(L, -2); | ||
| 151 | lua_setfenv(L, -2); | ||
| 149 | return 0; | 152 | return 0; |
| 150 | } | 153 | } |
| 151 | else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) | 154 | else if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) |
