summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ldblib.c9
-rw-r--r--ldebug.c7
2 files changed, 11 insertions, 5 deletions
diff --git a/ldblib.c b/ldblib.c
index c50568ae..b8164d51 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldblib.c,v 1.146 2014/11/10 14:27:16 roberto Exp roberto $
+** $Id: ldblib.c,v 1.147 2014/12/08 15:47:25 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@@ -207,15 +207,20 @@ static int db_getlocal (lua_State *L) {
static int db_setlocal (lua_State *L) {
int arg;
+ const char *name;
lua_State *L1 = getthread(L, &arg);
lua_Debug ar;
int level = (int)luaL_checkinteger(L, arg + 1);
+ int nvar = (int)luaL_checkinteger(L, arg + 2);
if (!lua_getstack(L1, level, &ar)) /* out of range? */
return luaL_argerror(L, arg+1, "level out of range");
luaL_checkany(L, arg+3);
lua_settop(L, arg+3);
lua_xmove(L, L1, 1);
- lua_pushstring(L, lua_setlocal(L1, &ar, (int)luaL_checkinteger(L, arg+2)));
+ name = lua_setlocal(L1, &ar, nvar);
+ if (name == NULL)
+ lua_pop(L1, 1); /* pop value (if not popped by 'lua_setlocal') */
+ lua_pushstring(L, name);
return 1;
}
diff --git a/ldebug.c b/ldebug.c
index 577114e6..93bfc002 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldebug.c,v 2.108 2014/12/08 15:48:23 roberto Exp roberto $
+** $Id: ldebug.c,v 2.109 2014/12/10 11:30:09 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -167,9 +167,10 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
StkId pos = 0; /* to avoid warnings */
const char *name = findlocal(L, ar->i_ci, n, &pos);
lua_lock(L);
- if (name)
+ if (name) {
setobjs2s(L, pos, L->top - 1);
- L->top--; /* pop value */
+ L->top--; /* pop value */
+ }
lua_unlock(L);
return name;
}