diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-10-25 15:30:15 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-10-25 15:30:15 -0300 |
commit | 34840301b529686ce8168828b140a478a5d44b53 (patch) | |
tree | daceb3978c3d40fd135fb60e9e60dbff9a47731c /ldo.c | |
parent | 41c800b352149e037bdebd5f20d2f25ed2a0e2a5 (diff) | |
download | lua-34840301b529686ce8168828b140a478a5d44b53.tar.gz lua-34840301b529686ce8168828b140a478a5d44b53.tar.bz2 lua-34840301b529686ce8168828b140a478a5d44b53.zip |
To-be-closed variables in the C API
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 32 |
1 files changed, 19 insertions, 13 deletions
@@ -366,32 +366,38 @@ void luaD_tryfuncTM (lua_State *L, StkId func) { | |||
366 | ** separated. | 366 | ** separated. |
367 | */ | 367 | */ |
368 | static void moveresults (lua_State *L, StkId res, int nres, int wanted) { | 368 | static void moveresults (lua_State *L, StkId res, int nres, int wanted) { |
369 | StkId firstresult; | ||
370 | int i; | ||
369 | switch (wanted) { /* handle typical cases separately */ | 371 | switch (wanted) { /* handle typical cases separately */ |
370 | case 0: /* no values needed */ | 372 | case 0: /* no values needed */ |
371 | L->top = res; | 373 | L->top = res; |
372 | break; | 374 | return; |
373 | case 1: /* one value needed */ | 375 | case 1: /* one value needed */ |
374 | if (nres == 0) /* no results? */ | 376 | if (nres == 0) /* no results? */ |
375 | setnilvalue(s2v(res)); /* adjust with nil */ | 377 | setnilvalue(s2v(res)); /* adjust with nil */ |
376 | else | 378 | else |
377 | setobjs2s(L, res, L->top - nres); /* move it to proper place */ | 379 | setobjs2s(L, res, L->top - nres); /* move it to proper place */ |
378 | L->top = res + 1; | 380 | L->top = res + 1; |
379 | break; | 381 | return; |
380 | case LUA_MULTRET: | 382 | case LUA_MULTRET: |
381 | wanted = nres; /* we want all results */ | 383 | wanted = nres; /* we want all results */ |
382 | /* FALLTHROUGH */ | ||
383 | default: { /* multiple results */ | ||
384 | StkId firstresult = L->top - nres; /* index of first result */ | ||
385 | int i; | ||
386 | /* move all results to correct place */ | ||
387 | for (i = 0; i < nres && i < wanted; i++) | ||
388 | setobjs2s(L, res + i, firstresult + i); | ||
389 | for (; i < wanted; i++) /* complete wanted number of results */ | ||
390 | setnilvalue(s2v(res + i)); | ||
391 | L->top = res + wanted; /* top points after the last result */ | ||
392 | break; | 384 | break; |
393 | } | 385 | default: /* multiple results (or to-be-closed variables) */ |
386 | if (hastocloseCfunc(wanted)) { | ||
387 | luaF_close(L, res, LUA_OK); | ||
388 | wanted = codeNresults(wanted); /* correct value */ | ||
389 | if (wanted == LUA_MULTRET) | ||
390 | wanted = nres; | ||
391 | } | ||
392 | break; | ||
394 | } | 393 | } |
394 | firstresult = L->top - nres; /* index of first result */ | ||
395 | /* move all results to correct place */ | ||
396 | for (i = 0; i < nres && i < wanted; i++) | ||
397 | setobjs2s(L, res + i, firstresult + i); | ||
398 | for (; i < wanted; i++) /* complete wanted number of results */ | ||
399 | setnilvalue(s2v(res + i)); | ||
400 | L->top = res + wanted; /* top points after the last result */ | ||
395 | } | 401 | } |
396 | 402 | ||
397 | 403 | ||