diff options
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 40 |
1 files changed, 1 insertions, 39 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.238 2010/03/19 15:52:48 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.239 2010/03/22 18:28:03 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 | */ |
@@ -107,50 +107,12 @@ static int luaB_setmetatable (lua_State *L) { | |||
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | |||
111 | #if defined(LUA_COMPAT_FENV) | ||
112 | |||
113 | static void getfunc (lua_State *L, int opt) { | ||
114 | if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); | ||
115 | else { | ||
116 | lua_Debug ar; | ||
117 | int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1); | ||
118 | luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); | ||
119 | if (lua_getstack(L, level, &ar) == 0) | ||
120 | luaL_argerror(L, 1, "invalid level"); | ||
121 | lua_getinfo(L, "f", &ar); | ||
122 | } | ||
123 | } | ||
124 | |||
125 | static int luaB_getfenv (lua_State *L) { | ||
126 | getfunc(L, 1); | ||
127 | if (lua_iscfunction(L, -1)) /* is a C function? */ | ||
128 | lua_pushglobaltable(L); /* return the global env. */ | ||
129 | else | ||
130 | lua_getfenv(L, -1); | ||
131 | return 1; | ||
132 | } | ||
133 | |||
134 | static int luaB_setfenv (lua_State *L) { | ||
135 | luaL_checktype(L, 2, LUA_TTABLE); | ||
136 | getfunc(L, 0); | ||
137 | lua_pushvalue(L, 2); | ||
138 | if (lua_iscfunction(L, -2) || lua_setfenv(L, -2) == 0) | ||
139 | return luaL_error(L, | ||
140 | LUA_QL("setfenv") " cannot change environment of given object"); | ||
141 | return 1; | ||
142 | } | ||
143 | |||
144 | #else | ||
145 | |||
146 | static int luaB_getfenv (lua_State *L) { | 110 | static int luaB_getfenv (lua_State *L) { |
147 | return luaL_error(L, "getfenv/setfenv deprecated"); | 111 | return luaL_error(L, "getfenv/setfenv deprecated"); |
148 | } | 112 | } |
149 | 113 | ||
150 | #define luaB_setfenv luaB_getfenv | 114 | #define luaB_setfenv luaB_getfenv |
151 | 115 | ||
152 | #endif | ||
153 | |||
154 | 116 | ||
155 | static int luaB_rawequal (lua_State *L) { | 117 | static int luaB_rawequal (lua_State *L) { |
156 | luaL_checkany(L, 1); | 118 | luaL_checkany(L, 1); |