diff options
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -173,15 +173,17 @@ LUA_API void lua_settop (lua_State *L, int idx) { | |||
173 | StkId func = L->ci->func; | 173 | StkId func = L->ci->func; |
174 | lua_lock(L); | 174 | lua_lock(L); |
175 | if (idx >= 0) { | 175 | if (idx >= 0) { |
176 | StkId newtop = (func + 1) + idx; | ||
176 | api_check(L, idx <= L->stack_last - (func + 1), "new top too large"); | 177 | api_check(L, idx <= L->stack_last - (func + 1), "new top too large"); |
177 | while (L->top < (func + 1) + idx) | 178 | while (L->top < newtop) |
178 | setnilvalue(s2v(L->top++)); | 179 | setnilvalue(s2v(L->top++)); |
179 | L->top = (func + 1) + idx; | 180 | L->top = newtop; |
180 | } | 181 | } |
181 | else { | 182 | else { |
182 | api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top"); | 183 | api_check(L, -(idx+1) <= (L->top - (func + 1)), "invalid new top"); |
183 | L->top += idx+1; /* 'subtract' index (index is negative) */ | 184 | L->top += idx+1; /* 'subtract' index (index is negative) */ |
184 | } | 185 | } |
186 | luaF_close(L, L->top, LUA_OK); | ||
185 | lua_unlock(L); | 187 | lua_unlock(L); |
186 | } | 188 | } |
187 | 189 | ||
@@ -1205,6 +1207,15 @@ LUA_API int lua_next (lua_State *L, int idx) { | |||
1205 | } | 1207 | } |
1206 | 1208 | ||
1207 | 1209 | ||
1210 | LUA_API void lua_tobeclosed (lua_State *L) { | ||
1211 | int nresults = L->ci->nresults; | ||
1212 | luaF_newtbcupval(L, L->top - 1); /* create new to-be-closed upvalue */ | ||
1213 | if (!hastocloseCfunc(nresults)) /* function not marked yet? */ | ||
1214 | L->ci->nresults = codeNresults(nresults); /* mark it */ | ||
1215 | lua_assert(hastocloseCfunc(L->ci->nresults)); | ||
1216 | } | ||
1217 | |||
1218 | |||
1208 | LUA_API void lua_concat (lua_State *L, int n) { | 1219 | LUA_API void lua_concat (lua_State *L, int n) { |
1209 | lua_lock(L); | 1220 | lua_lock(L); |
1210 | api_checknelems(L, n); | 1221 | api_checknelems(L, n); |