aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lbaselib.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 556325af..5f7e6658 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.195 2006/10/24 19:46:12 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.196 2007/02/07 17:51:21 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*/
@@ -114,11 +114,11 @@ static int luaB_setmetatable (lua_State *L) {
114} 114}
115 115
116 116
117static void getfunc (lua_State *L) { 117static void getfunc (lua_State *L, int opt) {
118 if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); 118 if (lua_isfunction(L, 1)) lua_pushvalue(L, 1);
119 else { 119 else {
120 lua_Debug ar; 120 lua_Debug ar;
121 int level = luaL_optint(L, 1, 1); 121 int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1);
122 luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); 122 luaL_argcheck(L, level >= 0, 1, "level must be non-negative");
123 if (lua_getstack(L, level, &ar) == 0) 123 if (lua_getstack(L, level, &ar) == 0)
124 luaL_argerror(L, 1, "invalid level"); 124 luaL_argerror(L, 1, "invalid level");
@@ -131,7 +131,7 @@ static void getfunc (lua_State *L) {
131 131
132 132
133static int luaB_getfenv (lua_State *L) { 133static int luaB_getfenv (lua_State *L) {
134 getfunc(L); 134 getfunc(L, 1);
135 if (lua_iscfunction(L, -1)) /* is a C function? */ 135 if (lua_iscfunction(L, -1)) /* is a C function? */
136 lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ 136 lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */
137 else 137 else
@@ -142,7 +142,7 @@ static int luaB_getfenv (lua_State *L) {
142 142
143static int luaB_setfenv (lua_State *L) { 143static int luaB_setfenv (lua_State *L) {
144 luaL_checktype(L, 2, LUA_TTABLE); 144 luaL_checktype(L, 2, LUA_TTABLE);
145 getfunc(L); 145 getfunc(L, 0);
146 lua_pushvalue(L, 2); 146 lua_pushvalue(L, 2);
147 if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { 147 if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) {
148 /* change environment of current thread */ 148 /* change environment of current thread */