diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-01-02 10:52:22 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-01-02 10:52:22 -0200 |
commit | 3a29087cb7d08a2693c9eecd82cf2ce13551e450 (patch) | |
tree | e8c3c75357b07b8f7099f49073ad0a4fcce81d34 /ldblib.c | |
parent | 234fb7f695f9e98fea40cc58b3cd2468e1ee0562 (diff) | |
download | lua-github-3a29087cb7d08a2693c9eecd82cf2ce13551e450.tar.gz |
'lua_setlocal' should not pop value when failing (to be consistent
with the manual and with 'lua_setupvalue')
Diffstat (limited to 'ldblib.c')
-rw-r--r-- | ldblib.c | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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; } |