aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-29 11:41:56 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-08-29 11:41:56 -0300
commit4e56c0d51412817a238f9de6453aaa16704a770d (patch)
tree0a73178d345df961f32cf167dc6a92a5813ab6ed
parentac12f4db4b2f715b1556722b6ed65804cfd6348a (diff)
downloadlua-4e56c0d51412817a238f9de6453aaa16704a770d.tar.gz
lua-4e56c0d51412817a238f9de6453aaa16704a770d.tar.bz2
lua-4e56c0d51412817a238f9de6453aaa16704a770d.zip
better implementation for luaV_pack
-rw-r--r--lbuiltin.c8
-rw-r--r--lvm.c27
-rw-r--r--lvm.h4
3 files changed, 16 insertions, 23 deletions
diff --git a/lbuiltin.c b/lbuiltin.c
index 81f05568..b0399941 100644
--- a/lbuiltin.c
+++ b/lbuiltin.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuiltin.c,v 1.122 2000/08/28 17:57:04 roberto Exp roberto $ 2** $Id: lbuiltin.c,v 1.123 2000/08/29 14:33:31 roberto Exp roberto $
3** Built-in functions 3** Built-in functions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -333,7 +333,6 @@ int luaB_call (lua_State *L) {
333 for (i=0; i<n; i++) 333 for (i=0; i<n; i++)
334 *(L->top++) = *luaH_getnum(arg, i+1); 334 *(L->top++) = *luaH_getnum(arg, i+1);
335 status = lua_call(L, n, LUA_MULTRET); 335 status = lua_call(L, n, LUA_MULTRET);
336 n = lua_gettop(L) - oldtop; /* number of results */
337 if (err != 0) { /* restore old error method */ 336 if (err != 0) { /* restore old error method */
338 lua_pushobject(L, err); 337 lua_pushobject(L, err);
339 lua_setglobal(L, LUA_ERRORMESSAGE); 338 lua_setglobal(L, LUA_ERRORMESSAGE);
@@ -347,12 +346,11 @@ int luaB_call (lua_State *L) {
347 } 346 }
348 else { /* no errors */ 347 else { /* no errors */
349 if (strchr(options, 'p')) { /* pack results? */ 348 if (strchr(options, 'p')) { /* pack results? */
350 luaV_pack(L, luaA_index(L, oldtop+1), n, L->top); 349 luaV_pack(L, luaA_index(L, oldtop+1));
351 incr_top;
352 return 1; /* only table is returned */ 350 return 1; /* only table is returned */
353 } 351 }
354 else 352 else
355 return n; /* results are already on the stack */ 353 return lua_gettop(L) - oldtop; /* results are already on the stack */
356 } 354 }
357} 355}
358 356
diff --git a/lvm.c b/lvm.c
index ed85e74c..9a651b6f 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.128 2000/08/22 20:49:29 roberto Exp roberto $ 2** $Id: lvm.c,v 1.129 2000/08/22 20:53:30 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -313,30 +313,25 @@ static void strconc (lua_State *L, int total, StkId top) {
313} 313}
314 314
315 315
316void luaV_pack (lua_State *L, StkId firstelem, int nvararg, TObject *tab) { 316void luaV_pack (lua_State *L, StkId firstelem) {
317 int i; 317 int i;
318 Hash *htab; 318 Hash *htab = luaH_new(L, 0);
319 htab = hvalue(tab) = luaH_new(L, nvararg+1); /* +1 for field `n' */ 319 for (i=0; firstelem+i<L->top; i++)
320 ttype(tab) = TAG_TABLE;
321 for (i=0; i<nvararg; i++)
322 *luaH_setint(L, htab, i+1) = *(firstelem+i); 320 *luaH_setint(L, htab, i+1) = *(firstelem+i);
323 /* store counter in field `n' */ 321 /* store counter in field `n' */
324 luaH_setstrnum(L, htab, luaS_new(L, "n"), nvararg); 322 luaH_setstrnum(L, htab, luaS_new(L, "n"), i);
323 L->top = firstelem; /* remove elements from the stack */
324 ttype(L->top) = TAG_TABLE;
325 hvalue(L->top) = htab;
326 incr_top;
325} 327}
326 328
327 329
328static void adjust_varargs (lua_State *L, StkId base, int nfixargs) { 330static void adjust_varargs (lua_State *L, StkId base, int nfixargs) {
329 TObject arg;
330 int nvararg = (L->top-base) - nfixargs; 331 int nvararg = (L->top-base) - nfixargs;
331 if (nvararg < 0) { 332 if (nvararg < 0)
332 luaV_pack(L, base, 0, &arg);
333 luaD_adjusttop(L, base, nfixargs); 333 luaD_adjusttop(L, base, nfixargs);
334 } 334 luaV_pack(L, base+nfixargs);
335 else {
336 luaV_pack(L, base+nfixargs, nvararg, &arg);
337 L->top = base+nfixargs;
338 }
339 *L->top++ = arg;
340} 335}
341 336
342 337
diff --git a/lvm.h b/lvm.h
index 01fc6f92..a85673c4 100644
--- a/lvm.h
+++ b/lvm.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.h,v 1.22 2000/05/08 19:32:53 roberto Exp roberto $ 2** $Id: lvm.h,v 1.23 2000/06/06 16:31:41 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -17,7 +17,7 @@
17#define tostring(L,o) ((ttype(o) != TAG_STRING) && (luaV_tostring(L, o) != 0)) 17#define tostring(L,o) ((ttype(o) != TAG_STRING) && (luaV_tostring(L, o) != 0))
18 18
19 19
20void luaV_pack (lua_State *L, StkId firstel, int nvararg, TObject *tab); 20void luaV_pack (lua_State *L, StkId firstel);
21int luaV_tonumber (TObject *obj); 21int luaV_tonumber (TObject *obj);
22int luaV_tostring (lua_State *L, TObject *obj); 22int luaV_tostring (lua_State *L, TObject *obj);
23void luaV_gettable (lua_State *L, StkId top); 23void luaV_gettable (lua_State *L, StkId top);