aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c26
1 files changed, 7 insertions, 19 deletions
diff --git a/lbaselib.c b/lbaselib.c
index d26bc7b0..d0dd1e9f 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.30 2001/03/07 12:43:52 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.31 2001/03/26 14:31:49 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -366,30 +366,19 @@ static int luaB_require (lua_State *L) {
366} 366}
367 367
368 368
369static int luaB_pack (lua_State *L) { 369static int aux_unwrap (lua_State *L, int arg) {
370 int n = lua_gettop(L);
371 lua_newtable(L);
372 aux_setn(L, -3, n);
373 lua_insert(L, 1);
374 while (n)
375 lua_rawseti(L, 1, n--);
376 return 1;
377}
378
379
380static int aux_unpack (lua_State *L, int arg) {
381 int n, i; 370 int n, i;
382 luaL_checktype(L, arg, LUA_TTABLE); 371 luaL_checktype(L, arg, LUA_TTABLE);
383 n = lua_getn(L, arg); 372 n = lua_getn(L, arg);
384 luaL_checkstack(L, n, l_s("too many arguments")); 373 luaL_checkstack(L, n, l_s("table too big to unwrap"));
385 for (i=1; i<=n; i++) /* push arg[1...n] */ 374 for (i=1; i<=n; i++) /* push arg[1...n] */
386 lua_rawgeti(L, arg, i); 375 lua_rawgeti(L, arg, i);
387 return n; 376 return n;
388} 377}
389 378
390 379
391static int luaB_unpack (lua_State *L) { 380static int luaB_unwrap (lua_State *L) {
392 return aux_unpack(L, 1); 381 return aux_unwrap(L, 1);
393} 382}
394 383
395 384
@@ -408,7 +397,7 @@ static int luaB_call (lua_State *L) {
408 oldtop = lua_gettop(L); /* top before function-call preparation */ 397 oldtop = lua_gettop(L); /* top before function-call preparation */
409 /* push function */ 398 /* push function */
410 lua_pushvalue(L, 1); 399 lua_pushvalue(L, 1);
411 n = aux_unpack(L, 2); /* push arg[1...n] */ 400 n = aux_unwrap(L, 2); /* push arg[1...n] */
412 status = lua_call(L, n, LUA_MULTRET); 401 status = lua_call(L, n, LUA_MULTRET);
413 if (err != 0) { /* restore old error method */ 402 if (err != 0) { /* restore old error method */
414 lua_pushvalue(L, err); 403 lua_pushvalue(L, err);
@@ -762,8 +751,7 @@ static const luaL_reg base_funcs[] = {
762 {l_s("sort"), luaB_sort}, 751 {l_s("sort"), luaB_sort},
763 {l_s("tinsert"), luaB_tinsert}, 752 {l_s("tinsert"), luaB_tinsert},
764 {l_s("tremove"), luaB_tremove}, 753 {l_s("tremove"), luaB_tremove},
765 {l_s("pack"), luaB_pack}, 754 {l_s("unwrap"), luaB_unwrap},
766 {l_s("unpack"), luaB_unpack},
767 {l_s("xtype"), luaB_xtype}, 755 {l_s("xtype"), luaB_xtype},
768}; 756};
769 757