diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-09-24 18:46:44 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-09-24 18:46:44 -0300 |
commit | e5ec547eb36090bb884378a23743a60e4f9f8bb7 (patch) | |
tree | c9bcba8846caae9c89cce8884d9e2eea426b7500 | |
parent | 6d383202dca4535866a339f17202e40b2775d160 (diff) | |
download | lua-e5ec547eb36090bb884378a23743a60e4f9f8bb7.tar.gz lua-e5ec547eb36090bb884378a23743a60e4f9f8bb7.tar.bz2 lua-e5ec547eb36090bb884378a23743a60e4f9f8bb7.zip |
"call" returns separate results, instead of a table.
-rw-r--r-- | inout.c | 17 | ||||
-rw-r--r-- | opcode.c | 30 | ||||
-rw-r--r-- | opcode.h | 3 |
3 files changed, 17 insertions, 33 deletions
@@ -5,7 +5,7 @@ | |||
5 | ** Also provides some predefined lua functions. | 5 | ** Also provides some predefined lua functions. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | char *rcs_inout="$Id: inout.c,v 2.40 1996/09/11 21:53:02 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.41 1996/09/24 17:30:28 roberto Exp roberto $"; |
9 | 9 | ||
10 | #include <stdio.h> | 10 | #include <stdio.h> |
11 | #include <string.h> | 11 | #include <string.h> |
@@ -281,15 +281,13 @@ void luaI_call (void) | |||
281 | temp = lua_getsubscript(); | 281 | temp = lua_getsubscript(); |
282 | narg = lua_isnumber(temp) ? lua_getnumber(temp) : MAXPARAMS+1; | 282 | narg = lua_isnumber(temp) ? lua_getnumber(temp) : MAXPARAMS+1; |
283 | /* read arg[1...n] */ | 283 | /* read arg[1...n] */ |
284 | for (i=0; i<narg; i++) | 284 | for (i=0; i<narg; i++) { |
285 | { | ||
286 | if (i>=MAXPARAMS) | 285 | if (i>=MAXPARAMS) |
287 | lua_error("argument list too long in function `call'"); | 286 | lua_error("argument list too long in function `call'"); |
288 | lua_pushobject(arg); | 287 | lua_pushobject(arg); |
289 | lua_pushnumber(i+1); | 288 | lua_pushnumber(i+1); |
290 | params[i] = lua_getsubscript(); | 289 | params[i] = lua_getsubscript(); |
291 | if (narg == MAXPARAMS+1 && lua_isnil(params[i])) | 290 | if (narg == MAXPARAMS+1 && lua_isnil(params[i])) { |
292 | { | ||
293 | narg = i; | 291 | narg = i; |
294 | break; | 292 | break; |
295 | } | 293 | } |
@@ -298,14 +296,7 @@ void luaI_call (void) | |||
298 | for (i=0; i<narg; i++) | 296 | for (i=0; i<narg; i++) |
299 | lua_pushobject(params[i]); | 297 | lua_pushobject(params[i]); |
300 | if (lua_callfunction(f)) | 298 | if (lua_callfunction(f)) |
301 | { /* error */ | ||
302 | lua_error(NULL); | 299 | lua_error(NULL); |
303 | } | ||
304 | else | 300 | else |
305 | { /* push results */ | 301 | passresults(); |
306 | Object r; | ||
307 | arg = lua_getresult(1); | ||
308 | luaI_packarg((arg == LUA_NOOBJECT)?NULL:luaI_Address(arg), &r); | ||
309 | luaI_pushobject(&r); | ||
310 | } | ||
311 | } | 302 | } |
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.74 1996/09/20 12:51:16 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.75 1996/09/24 17:30:28 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <setjmp.h> | 8 | #include <setjmp.h> |
9 | #include <stdio.h> | 9 | #include <stdio.h> |
@@ -897,41 +897,35 @@ static void comparison (lua_Type tag_less, lua_Type tag_equal, | |||
897 | } | 897 | } |
898 | 898 | ||
899 | 899 | ||
900 | void luaI_packarg (Object *firstelem, Object *arg) | 900 | static void adjust_varargs (StkId first_extra_arg) |
901 | { | 901 | { |
902 | int nvararg = (firstelem != NULL) ? top-firstelem : 0; | 902 | Object arg; |
903 | Object *firstelem = stack+first_extra_arg; | ||
904 | int nvararg = top-firstelem; | ||
903 | int i; | 905 | int i; |
904 | if (nvararg < 0) nvararg = 0; | 906 | if (nvararg < 0) nvararg = 0; |
905 | avalue(arg) = lua_createarray(nvararg+1); /* +1 for field 'n' */ | 907 | avalue(&arg) = lua_createarray(nvararg+1); /* +1 for field 'n' */ |
906 | tag(arg) = LUA_T_ARRAY; | 908 | tag(&arg) = LUA_T_ARRAY; |
907 | for (i=0; i<nvararg; i++) | 909 | for (i=0; i<nvararg; i++) { |
908 | { | ||
909 | Object index; | 910 | Object index; |
910 | tag(&index) = LUA_T_NUMBER; | 911 | tag(&index) = LUA_T_NUMBER; |
911 | nvalue(&index) = i+1; | 912 | nvalue(&index) = i+1; |
912 | *(lua_hashdefine(avalue(arg), &index)) = *(firstelem+i); | 913 | *(lua_hashdefine(avalue(&arg), &index)) = *(firstelem+i); |
913 | } | 914 | } |
914 | /* store counter in field "n" */ | 915 | /* store counter in field "n" */ { |
915 | { | ||
916 | Object index, extra; | 916 | Object index, extra; |
917 | tag(&index) = LUA_T_STRING; | 917 | tag(&index) = LUA_T_STRING; |
918 | tsvalue(&index) = lua_createstring("n"); | 918 | tsvalue(&index) = lua_createstring("n"); |
919 | tag(&extra) = LUA_T_NUMBER; | 919 | tag(&extra) = LUA_T_NUMBER; |
920 | nvalue(&extra) = nvararg; | 920 | nvalue(&extra) = nvararg; |
921 | *(lua_hashdefine(avalue(arg), &index)) = extra; | 921 | *(lua_hashdefine(avalue(&arg), &index)) = extra; |
922 | } | 922 | } |
923 | } | ||
924 | |||
925 | |||
926 | static void adjust_varargs (StkId first_extra_arg) | ||
927 | { | ||
928 | Object arg; | ||
929 | luaI_packarg(stack+first_extra_arg, &arg); | ||
930 | adjust_top(first_extra_arg); | 923 | adjust_top(first_extra_arg); |
931 | *top = arg; incr_top; | 924 | *top = arg; incr_top; |
932 | } | 925 | } |
933 | 926 | ||
934 | 927 | ||
928 | |||
935 | /* | 929 | /* |
936 | ** Execute the given opcode, until a RET. Parameters are between | 930 | ** Execute the given opcode, until a RET. Parameters are between |
937 | ** [stack+base,top). Returns n such that the the results are between | 931 | ** [stack+base,top). Returns n such that the the results are between |
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | ** TeCGraf - PUC-Rio | 2 | ** TeCGraf - PUC-Rio |
3 | ** $Id: opcode.h,v 3.20 1996/03/15 13:13:13 roberto Exp roberto $ | 3 | ** $Id: opcode.h,v 3.21 1996/05/28 21:07:32 roberto Exp roberto $ |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #ifndef opcode_h | 6 | #ifndef opcode_h |
@@ -122,6 +122,5 @@ Object *luaI_Address (lua_Object o); | |||
122 | void luaI_pushobject (Object *o); | 122 | void luaI_pushobject (Object *o); |
123 | void luaI_gcFB (Object *o); | 123 | void luaI_gcFB (Object *o); |
124 | int luaI_dorun (TFunc *tf); | 124 | int luaI_dorun (TFunc *tf); |
125 | void luaI_packarg (Object *firstelem, Object *arg); | ||
126 | 125 | ||
127 | #endif | 126 | #endif |