diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-11-02 09:48:59 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-11-02 09:48:59 -0200 |
| commit | ffd0d1232d3a681b3db960d3c30721c3090587d0 (patch) | |
| tree | 5172fed804f5e2cf8eece1d483b5a5b1109ebb01 | |
| parent | 07a2dcacbfb8f9a2332da19b5c5a178e87d7af21 (diff) | |
| download | lua-ffd0d1232d3a681b3db960d3c30721c3090587d0.tar.gz lua-ffd0d1232d3a681b3db960d3c30721c3090587d0.tar.bz2 lua-ffd0d1232d3a681b3db960d3c30721c3090587d0.zip | |
using more "conventional" loops in 'luaD_poscall' (probably a little
more efficient?)
| -rw-r--r-- | ldo.c | 20 |
1 files changed, 13 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.143 2015/10/28 12:25:36 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.144 2015/10/28 17:28:40 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -406,12 +406,18 @@ int luaD_poscall (lua_State *L, StkId firstResult, int nres) { | |||
| 406 | res = ci->func; /* res == final position of 1st result */ | 406 | res = ci->func; /* res == final position of 1st result */ |
| 407 | wanted = ci->nresults; | 407 | wanted = ci->nresults; |
| 408 | L->ci = ci->previous; /* back to caller */ | 408 | L->ci = ci->previous; /* back to caller */ |
| 409 | /* move results to correct place */ | 409 | /* comparison is 'unsigned' to make 'LUA_MULTRET' fails test */ |
| 410 | for (i = wanted; i != 0 && nres-- > 0; i--) | 410 | if ((unsigned int)wanted <= (unsigned int)nres) { /* enough results? */ |
| 411 | setobjs2s(L, res++, firstResult++); | 411 | for (i = 0; i < wanted; i++) /* move wanted results to correct place */ |
| 412 | while (i-- > 0) | 412 | setobjs2s(L, res + i, firstResult + i); |
| 413 | setnilvalue(res++); | 413 | } |
| 414 | L->top = res; | 414 | else { /* not enough results (or multret); use all of them plus nils */ |
| 415 | for (i = 0; i < nres; i++) /* move all results to correct place */ | ||
| 416 | setobjs2s(L, res + i, firstResult + i); | ||
| 417 | for (; i < wanted; i++) /* complete wanted number of results */ | ||
| 418 | setnilvalue(res + i); | ||
| 419 | } | ||
| 420 | L->top = res + i; /* top points after the last result */ | ||
| 415 | return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */ | 421 | return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */ |
| 416 | } | 422 | } |
| 417 | 423 | ||
