lua-users home
lua-l archive

Re: Possible bug in getfunc() in lbaselib.c (5.1.1)?

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Roberto Ierusalimschy <roberto <at> inf.puc-rio.br> writes:
> I am afraid this patch would disallow the call "getfenv()".
> 
> > A better solution to the general problem would be to propagate the error
> > from loadfile(), but I still think this is a bug in setfenv().
> 
> Yes (using "assert") and yes.
How about if luaB_getfenv explicitly push a '1' when it gets no arguments?
Index: D:/Downloads/Interpreters/lua/lua-5.1.1/src/lbaselib.c
===================================================================
--- D:/Downloads/Interpreters/lua/lua-5.1.1/src/lbaselib.c	(revision 4)
+++ D:/Downloads/Interpreters/lua/lua-5.1.1/src/lbaselib.c	(working copy)
@@ -118,7 +118,7 @@
 if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
 else {
 lua_Debug ar;
- int level = luaL_optint(L, 1, 1);
+ int level = luaL_checkint(L, 1);
 luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
 if (lua_getstack(L, level, &ar) == 0)
 luaL_argerror(L, 1, "invalid level");
@@ -131,6 +131,7 @@
 
 
 static int luaB_getfenv (lua_State *L) {
+ if (lua_gettop(L) == 0 ) lua_pushinteger(L, 1);
 getfunc(L);
 if (lua_iscfunction(L, -1)) /* is a C function? */
 lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */

AltStyle によって変換されたページ (->オリジナル) /