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