aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c17
1 files changed, 2 insertions, 15 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 6ce9f18e..a4c3db6f 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -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
132static 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
140static int luaB_getfenv (lua_State *L) { 132static 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) {
148static int luaB_setfenv (lua_State *L) { 139static 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);