Auxiliary buffer cannot close box with 'lua_remove'

To remove a to-be-closed variable from the stack in the C API a
function must use 'lua_settop' or 'lua_pop'. Previous implementation of
'luaL_pushresult' was not closing the box. (This commit also added
tests to check that box is being closed "as soon as possible".)
This commit is contained in:
Roberto Ierusalimschy
2018-11-26 14:16:17 -02:00
parent 7e63d3da02
commit 7696c6474f
3 changed files with 49 additions and 23 deletions

4
lapi.c
View File

@@ -1213,8 +1213,8 @@ LUA_API void lua_toclose (lua_State *L, int idx) {
lua_lock(L);
o = index2stack(L, idx);
nresults = L->ci->nresults;
api_check(L, L->openupval == NULL || uplevel(L->openupval) < o,
"there is an already marked index below");
api_check(L, L->openupval == NULL || uplevel(L->openupval) <= o,
"marked index below or equal new one");
luaF_newtbcupval(L, o); /* create new to-be-closed upvalue */
if (!hastocloseCfunc(nresults)) /* function not marked yet? */
L->ci->nresults = codeNresults(nresults); /* mark it */