mirror of https://github.com/rusefi/lua.git
BUG: setfenv accepts invalid argument
This commit is contained in:
parent
3bf0292cd5
commit
d3c304e92e
10
lbaselib.c
10
lbaselib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lbaselib.c,v 1.195 2006/10/24 19:46:12 roberto Exp roberto $
|
** $Id: lbaselib.c,v 1.196 2007/02/07 17:51:21 roberto Exp roberto $
|
||||||
** Basic library
|
** Basic library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -114,11 +114,11 @@ static int luaB_setmetatable (lua_State *L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void getfunc (lua_State *L) {
|
static void getfunc (lua_State *L, int opt) {
|
||||||
if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
|
if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
|
||||||
else {
|
else {
|
||||||
lua_Debug ar;
|
lua_Debug ar;
|
||||||
int level = luaL_optint(L, 1, 1);
|
int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1);
|
||||||
luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
|
luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
|
||||||
if (lua_getstack(L, level, &ar) == 0)
|
if (lua_getstack(L, level, &ar) == 0)
|
||||||
luaL_argerror(L, 1, "invalid level");
|
luaL_argerror(L, 1, "invalid level");
|
||||||
|
@ -131,7 +131,7 @@ static void getfunc (lua_State *L) {
|
||||||
|
|
||||||
|
|
||||||
static int luaB_getfenv (lua_State *L) {
|
static int luaB_getfenv (lua_State *L) {
|
||||||
getfunc(L);
|
getfunc(L, 1);
|
||||||
if (lua_iscfunction(L, -1)) /* is a C function? */
|
if (lua_iscfunction(L, -1)) /* is a C function? */
|
||||||
lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */
|
lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */
|
||||||
else
|
else
|
||||||
|
@ -142,7 +142,7 @@ static int luaB_getfenv (lua_State *L) {
|
||||||
|
|
||||||
static int luaB_setfenv (lua_State *L) {
|
static int luaB_setfenv (lua_State *L) {
|
||||||
luaL_checktype(L, 2, LUA_TTABLE);
|
luaL_checktype(L, 2, LUA_TTABLE);
|
||||||
getfunc(L);
|
getfunc(L, 0);
|
||||||
lua_pushvalue(L, 2);
|
lua_pushvalue(L, 2);
|
||||||
if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {
|
if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {
|
||||||
/* change environment of current thread */
|
/* change environment of current thread */
|
||||||
|
|
Loading…
Reference in New Issue