aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-02-12 07:11:01 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-02-12 07:11:01 -0200
commit4b6f436d67bd19adcea57f7a2db651b22310bf57 (patch)
tree589a198ee5c223735b882433620021591abea7c1 /lbaselib.c
parent8f105d6b5987fa97c7344c95c128f064766ca8e7 (diff)
downloadlua-4b6f436d67bd19adcea57f7a2db651b22310bf57.tar.gz
lua-4b6f436d67bd19adcea57f7a2db651b22310bf57.tar.bz2
lua-4b6f436d67bd19adcea57f7a2db651b22310bf57.zip
`unpack' uses `getn' to get table size
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/lbaselib.c b/lbaselib.c
index ce5e442f..bbb5cb88 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.116 2002/12/20 09:55:56 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.117 2003/02/10 10:21:31 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*/
@@ -295,20 +295,11 @@ static int luaB_assert (lua_State *L) {
295static int luaB_unpack (lua_State *L) { 295static int luaB_unpack (lua_State *L) {
296 int n, i; 296 int n, i;
297 luaL_checktype(L, 1, LUA_TTABLE); 297 luaL_checktype(L, 1, LUA_TTABLE);
298 lua_pushliteral(L, "n"); 298 n = luaL_getn(L, 1);
299 lua_rawget(L, 1); 299 luaL_checkstack(L, n, "table too big to unpack");
300 n = (lua_isnumber(L, -1)) ? (int)lua_tonumber(L, -1) : -1; 300 for (i=1; i<=n; i++) /* push arg[1...n] */
301 for (i=0; i<n || n==-1; i++) { /* push arg[1...n] */ 301 lua_rawgeti(L, 1, i);
302 luaL_checkstack(L, LUA_MINSTACK, "table too big to unpack"); 302 return n;
303 lua_rawgeti(L, 1, i+1);
304 if (n == -1) { /* no explicit limit? */
305 if (lua_isnil(L, -1)) { /* stop at first `nil' element */
306 lua_pop(L, 1); /* remove `nil' */
307 break;
308 }
309 }
310 }
311 return i;
312} 303}
313 304
314 305