mirror of https://github.com/rusefi/lua.git
no more `__fenv'
This commit is contained in:
parent
9d8426bab4
commit
50f9cd201e
17
lbaselib.c
17
lbaselib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lbaselib.c,v 1.143 2004/05/10 17:50:51 roberto Exp roberto $
|
** $Id: lbaselib.c,v 1.144 2004/05/31 18:50:30 roberto Exp roberto $
|
||||||
** Basic library
|
** Basic library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -129,18 +129,9 @@ static void getfunc (lua_State *L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int aux_getfenv (lua_State *L) {
|
|
||||||
lua_getfenv(L, -1);
|
|
||||||
lua_pushliteral(L, "__fenv");
|
|
||||||
lua_rawget(L, -2);
|
|
||||||
return !lua_isnil(L, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int luaB_getfenv (lua_State *L) {
|
static int luaB_getfenv (lua_State *L) {
|
||||||
getfunc(L);
|
getfunc(L);
|
||||||
if (!aux_getfenv(L)) /* __fenv not defined? */
|
lua_getfenv(L, -1);
|
||||||
lua_pop(L, 1); /* remove it, to return real environment */
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,10 +139,6 @@ static int luaB_getfenv (lua_State *L) {
|
||||||
static int luaB_setfenv (lua_State *L) {
|
static int luaB_setfenv (lua_State *L) {
|
||||||
luaL_checktype(L, 2, LUA_TTABLE);
|
luaL_checktype(L, 2, LUA_TTABLE);
|
||||||
getfunc(L);
|
getfunc(L);
|
||||||
if (aux_getfenv(L)) /* __fenv defined? */
|
|
||||||
luaL_error(L, "`setfenv' cannot change a protected environment");
|
|
||||||
else
|
|
||||||
lua_pop(L, 2); /* remove __fenv and real environment table */
|
|
||||||
lua_pushvalue(L, 2);
|
lua_pushvalue(L, 2);
|
||||||
if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0)
|
if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0)
|
||||||
lua_replace(L, LUA_GLOBALSINDEX);
|
lua_replace(L, LUA_GLOBALSINDEX);
|
||||||
|
|
Loading…
Reference in New Issue