aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/lapi.c b/lapi.c
index ae6b07ae..4fef43b7 100644
--- a/lapi.c
+++ b/lapi.c
@@ -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
1210LUA_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
1208LUA_API void lua_concat (lua_State *L, int n) { 1219LUA_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);