Browse Source

"call" returns separate results, instead of a table.

Roberto Ierusalimschy 29 years ago
parent
commit
e5ec547eb3
3 changed files with 17 additions and 33 deletions
  1. 4 13
      inout.c
  2. 12 18
      opcode.c
  3. 1 2
      opcode.h

+ 4 - 13
inout.c

@@ -5,7 +5,7 @@
 ** Also provides some predefined lua functions.
 */
 
-char *rcs_inout="$Id: inout.c,v 2.40 1996/09/11 21:53:02 roberto Exp roberto $";
+char *rcs_inout="$Id: inout.c,v 2.41 1996/09/24 17:30:28 roberto Exp roberto $";
 
 #include <stdio.h>
 #include <string.h>
@@ -281,15 +281,13 @@ void luaI_call (void)
   temp = lua_getsubscript();
   narg = lua_isnumber(temp) ? lua_getnumber(temp) : MAXPARAMS+1;
   /* read arg[1...n] */
-  for (i=0; i<narg; i++)
-  {
+  for (i=0; i<narg; i++) {
     if (i>=MAXPARAMS)
       lua_error("argument list too long in function `call'");
     lua_pushobject(arg);
     lua_pushnumber(i+1);
     params[i] = lua_getsubscript();
-    if (narg == MAXPARAMS+1 && lua_isnil(params[i]))
-    {
+    if (narg == MAXPARAMS+1 && lua_isnil(params[i])) {
       narg = i;
       break;
     }
@@ -298,14 +296,7 @@ void luaI_call (void)
   for (i=0; i<narg; i++)
     lua_pushobject(params[i]);
   if (lua_callfunction(f))
-  { /* error */
     lua_error(NULL);
-  }
   else
-  { /* push results */
-    Object r;
-    arg = lua_getresult(1);
-    luaI_packarg((arg == LUA_NOOBJECT)?NULL:luaI_Address(arg), &r);
-    luaI_pushobject(&r);
-  }
+    passresults();
 }

+ 12 - 18
opcode.c

@@ -3,7 +3,7 @@
 ** TecCGraf - PUC-Rio
 */
 
-char *rcs_opcode="$Id: opcode.c,v 3.74 1996/09/20 12:51:16 roberto Exp roberto $";
+char *rcs_opcode="$Id: opcode.c,v 3.75 1996/09/24 17:30:28 roberto Exp roberto $";
 
 #include <setjmp.h>
 #include <stdio.h>
@@ -897,41 +897,35 @@ static void comparison (lua_Type tag_less, lua_Type tag_equal,
 }
 
 
-void luaI_packarg (Object *firstelem, Object *arg)
+static void adjust_varargs (StkId first_extra_arg)
 {
-  int nvararg = (firstelem != NULL) ? top-firstelem : 0;
+  Object arg;
+  Object *firstelem = stack+first_extra_arg;
+  int nvararg = top-firstelem;
   int i;
   if (nvararg < 0) nvararg = 0;
-  avalue(arg)  = lua_createarray(nvararg+1);  /* +1 for field 'n' */
-  tag(arg) = LUA_T_ARRAY;
-  for (i=0; i<nvararg; i++)
-  {
+  avalue(&arg)  = lua_createarray(nvararg+1);  /* +1 for field 'n' */
+  tag(&arg) = LUA_T_ARRAY;
+  for (i=0; i<nvararg; i++) {
     Object index;
     tag(&index) = LUA_T_NUMBER;
     nvalue(&index) = i+1;
-    *(lua_hashdefine(avalue(arg), &index)) = *(firstelem+i);
+    *(lua_hashdefine(avalue(&arg), &index)) = *(firstelem+i);
   }
-  /* store counter in field "n" */
-  {
+  /* store counter in field "n" */ {
     Object index, extra;
     tag(&index) = LUA_T_STRING;
     tsvalue(&index) = lua_createstring("n");
     tag(&extra) = LUA_T_NUMBER;
     nvalue(&extra) = nvararg;
-    *(lua_hashdefine(avalue(arg), &index)) = extra;
+    *(lua_hashdefine(avalue(&arg), &index)) = extra;
   }
-}
-
-
-static void adjust_varargs (StkId first_extra_arg)
-{
-  Object arg;
-  luaI_packarg(stack+first_extra_arg, &arg);
   adjust_top(first_extra_arg);
   *top = arg; incr_top;
 }
 
 
+
 /*
 ** Execute the given opcode, until a RET. Parameters are between
 ** [stack+base,top). Returns n such that the the results are between

+ 1 - 2
opcode.h

@@ -1,6 +1,6 @@
 /*
 ** TeCGraf - PUC-Rio
-** $Id: opcode.h,v 3.20 1996/03/15 13:13:13 roberto Exp roberto $
+** $Id: opcode.h,v 3.21 1996/05/28 21:07:32 roberto Exp roberto $
 */
 
 #ifndef opcode_h
@@ -122,6 +122,5 @@ Object *luaI_Address (lua_Object o);
 void	luaI_pushobject (Object *o);
 void    luaI_gcFB       (Object *o);
 int     luaI_dorun (TFunc *tf);
-void	luaI_packarg (Object *firstelem, Object *arg);
 
 #endif