Browse Source

`setfenv' returns "self"

v5-2
Roberto Ierusalimschy 21 years ago
parent
commit
6311e3109f
  1. 8
      lbaselib.c

8
lbaselib.c

@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.145 2004/06/02 14:20:08 roberto Exp roberto $
** $Id: lbaselib.c,v 1.146 2004/06/04 15:30:53 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@ -140,11 +140,13 @@ static int luaB_setfenv (lua_State *L) {
luaL_checktype(L, 2, LUA_TTABLE);
getfunc(L);
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);
return 0;
}
else if (lua_setfenv(L, -2) == 0)
luaL_error(L, "`setfenv' cannot change environment of given function");
return 0;
return 1;
}

Loading…
Cancel
Save