diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-06-02 11:20:08 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-06-02 11:20:08 -0300 |
| commit | 50f9cd201e34f3464362a63c54207fff963507d0 (patch) | |
| tree | 99da34b12f6a4b31a6f76ccdebac0ed325f66c72 | |
| parent | 9d8426bab445935bb0c08f2ecefb2e208dc38747 (diff) | |
| download | lua-50f9cd201e34f3464362a63c54207fff963507d0.tar.gz lua-50f9cd201e34f3464362a63c54207fff963507d0.tar.bz2 lua-50f9cd201e34f3464362a63c54207fff963507d0.zip | |
no more `__fenv'
| -rw-r--r-- | lbaselib.c | 17 |
1 files changed, 2 insertions, 15 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.143 2004/05/10 17:50:51 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.144 2004/05/31 18:50:30 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 | */ |
| @@ -129,18 +129,9 @@ static void getfunc (lua_State *L) { | |||
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | 131 | ||
| 132 | static int aux_getfenv (lua_State *L) { | ||
| 133 | lua_getfenv(L, -1); | ||
| 134 | lua_pushliteral(L, "__fenv"); | ||
| 135 | lua_rawget(L, -2); | ||
| 136 | return !lua_isnil(L, -1); | ||
| 137 | } | ||
| 138 | |||
| 139 | |||
| 140 | static int luaB_getfenv (lua_State *L) { | 132 | static int luaB_getfenv (lua_State *L) { |
| 141 | getfunc(L); | 133 | getfunc(L); |
| 142 | if (!aux_getfenv(L)) /* __fenv not defined? */ | 134 | lua_getfenv(L, -1); |
| 143 | lua_pop(L, 1); /* remove it, to return real environment */ | ||
| 144 | return 1; | 135 | return 1; |
| 145 | } | 136 | } |
| 146 | 137 | ||
| @@ -148,10 +139,6 @@ static int luaB_getfenv (lua_State *L) { | |||
| 148 | static int luaB_setfenv (lua_State *L) { | 139 | static int luaB_setfenv (lua_State *L) { |
| 149 | luaL_checktype(L, 2, LUA_TTABLE); | 140 | luaL_checktype(L, 2, LUA_TTABLE); |
| 150 | getfunc(L); | 141 | getfunc(L); |
| 151 | if (aux_getfenv(L)) /* __fenv defined? */ | ||
| 152 | luaL_error(L, "`setfenv' cannot change a protected environment"); | ||
| 153 | else | ||
| 154 | lua_pop(L, 2); /* remove __fenv and real environment table */ | ||
| 155 | lua_pushvalue(L, 2); | 142 | lua_pushvalue(L, 2); |
| 156 | if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) | 143 | if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) |
| 157 | lua_replace(L, LUA_GLOBALSINDEX); | 144 | lua_replace(L, LUA_GLOBALSINDEX); |
