aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldo.c')
-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