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