| 172 | |
| 173 | |
| 174 | LUA_API void lua_settop (lua_State *L, int idx) { |
| 175 | CallInfo *ci; |
| 176 | StkId func, newtop; |
| 177 | ptrdiff_t diff; /* difference for new top */ |
| 178 | lua_lock(L); |
| 179 | ci = L->ci; |
| 180 | func = ci->func; |
| 181 | if (idx >= 0) { |
| 182 | api_check(L, idx <= ci->top - (func + 1), "new top too large"); |
| 183 | diff = ((func + 1) + idx) - L->top; |
| 184 | for (; diff > 0; diff--) |
| 185 | setnilvalue(s2v(L->top++)); /* clear new slots */ |
| 186 | } |
| 187 | else { |
| 188 | api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top"); |
| 189 | diff = idx + 1; /* will "subtract" index (as it is negative) */ |
| 190 | } |
| 191 | api_check(L, L->tbclist < L->top, "previous pop of an unclosed slot"); |
| 192 | newtop = L->top + diff; |
| 193 | if (diff < 0 && L->tbclist >= newtop) { |
| 194 | lua_assert(hastocloseCfunc(ci->nresults)); |
| 195 | luaF_close(L, newtop, CLOSEKTOP, 0); |
| 196 | } |
| 197 | L->top = newtop; /* correct top only after closing any upvalue */ |
| 198 | lua_unlock(L); |
| 199 | } |
| 200 | |
| 201 | |
| 202 | LUA_API void lua_closeslot (lua_State *L, int idx) { |
no test coverage detected