summaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-11-02 09:48:59 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-11-02 09:48:59 -0200
commitffd0d1232d3a681b3db960d3c30721c3090587d0 (patch)
tree5172fed804f5e2cf8eece1d483b5a5b1109ebb01 /ldo.c
parent07a2dcacbfb8f9a2332da19b5c5a178e87d7af21 (diff)
downloadlua-ffd0d1232d3a681b3db960d3c30721c3090587d0.tar.gz
lua-ffd0d1232d3a681b3db960d3c30721c3090587d0.tar.bz2
lua-ffd0d1232d3a681b3db960d3c30721c3090587d0.zip
using more "conventional" loops in 'luaD_poscall' (probably a little
more efficient?)
Diffstat (limited to '')
-rw-r--r--ldo.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/ldo.c b/ldo.c
index 0cb6173b..528f19e9 100644
--- a/ldo.c
+++ b/ldo.c
@@ -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