aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lbaselib.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 009db94b..563d3136 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.139 2003/12/09 16:55:43 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.140 2004/03/09 17:34:35 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*/
@@ -345,11 +345,15 @@ static int luaB_assert (lua_State *L) {
345 345
346 346
347static int luaB_unpack (lua_State *L) { 347static int luaB_unpack (lua_State *L) {
348 int n, i; 348 int i = luaL_optint(L, 2, 1);
349 int e = luaL_optint(L, 3, -1);
350 int n;
349 luaL_checktype(L, 1, LUA_TTABLE); 351 luaL_checktype(L, 1, LUA_TTABLE);
350 n = luaL_getn(L, 1); 352 if (e == -1) e = luaL_getn(L, 1);
353 n = e - i + 1; /* number of elements */
354 if (n <= 0) return 0; /* empty range */
351 luaL_checkstack(L, n, "table too big to unpack"); 355 luaL_checkstack(L, n, "table too big to unpack");
352 for (i=1; i<=n; i++) /* push arg[1...n] */ 356 for (; i<=e; i++) /* push arg[i...e] */
353 lua_rawgeti(L, 1, i); 357 lua_rawgeti(L, 1, i);
354 return n; 358 return n;
355} 359}