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