|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
-** $Id: lbaselib.c,v 1.121 2003/02/18 16:13:15 roberto Exp roberto $
|
|
|
+** $Id: lbaselib.c,v 1.122 2003/02/24 16:50:41 roberto Exp roberto $
|
|
|
** Basic library
|
|
|
** See Copyright Notice in lua.h
|
|
|
*/
|
|
@@ -127,31 +127,31 @@ static void getfunc (lua_State *L) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-static int aux_getenvtable (lua_State *L) {
|
|
|
- lua_getenvtable(L, -1);
|
|
|
+static int aux_getfenv (lua_State *L) {
|
|
|
+ lua_getfenv(L, -1);
|
|
|
lua_pushliteral(L, "__globals");
|
|
|
lua_rawget(L, -2);
|
|
|
return !lua_isnil(L, -1);
|
|
|
}
|
|
|
|
|
|
|
|
|
-static int luaB_getenvtable (lua_State *L) {
|
|
|
+static int luaB_getfenv (lua_State *L) {
|
|
|
getfunc(L);
|
|
|
- if (!aux_getenvtable(L)) /* __globals not defined? */
|
|
|
+ if (!aux_getfenv(L)) /* __globals not defined? */
|
|
|
lua_pop(L, 1); /* remove it, to return real environment */
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
|
|
|
-static int luaB_setenvtable (lua_State *L) {
|
|
|
+static int luaB_setfenv (lua_State *L) {
|
|
|
luaL_checktype(L, 2, LUA_TTABLE);
|
|
|
getfunc(L);
|
|
|
- if (aux_getenvtable(L)) /* __globals defined? */
|
|
|
+ if (aux_getfenv(L)) /* __globals defined? */
|
|
|
luaL_error(L, "cannot change a protected global table");
|
|
|
else
|
|
|
lua_pop(L, 2); /* remove __globals and real environment table */
|
|
|
lua_pushvalue(L, 2);
|
|
|
- if (lua_setenvtable(L, -2) == 0)
|
|
|
+ if (lua_setfenv(L, -2) == 0)
|
|
|
luaL_error(L, "cannot change environment of given function");
|
|
|
return 0;
|
|
|
}
|
|
@@ -247,8 +247,8 @@ static int load_aux (lua_State *L, int status) {
|
|
|
lua_Debug ar;
|
|
|
lua_getstack(L, 1, &ar);
|
|
|
lua_getinfo(L, "f", &ar); /* get calling function */
|
|
|
- lua_getenvtable(L, -1); /* get its environment */
|
|
|
- lua_setenvtable(L, -3); /* set it as the environment of the new chunk */
|
|
|
+ lua_getfenv(L, -1); /* get its environment */
|
|
|
+ lua_setfenv(L, -3); /* set it as the environment of the new chunk */
|
|
|
lua_pop(L, 1); /* remove calling function */
|
|
|
return 1;
|
|
|
}
|
|
@@ -499,8 +499,8 @@ static const luaL_reg base_funcs[] = {
|
|
|
{"error", luaB_error},
|
|
|
{"getmetatable", luaB_getmetatable},
|
|
|
{"setmetatable", luaB_setmetatable},
|
|
|
- {"getenvtable", luaB_getenvtable},
|
|
|
- {"setenvtable", luaB_setenvtable},
|
|
|
+ {"getfenv", luaB_getfenv},
|
|
|
+ {"setfenv", luaB_setfenv},
|
|
|
{"next", luaB_next},
|
|
|
{"ipairs", luaB_ipairs},
|
|
|
{"pairs", luaB_pairs},
|