`setfenv' returns "self"

This commit is contained in:
Roberto Ierusalimschy 2004-06-15 10:31:30 -03:00
parent 9b854e6dbc
commit 6311e3109f
1 changed files with 5 additions and 3 deletions

View File

@ -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;
}