aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/lbaselib.c b/lbaselib.c
index aeb213b9..40567969 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.85 2002/06/25 19:19:33 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.86 2002/06/26 16:37:13 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*/
@@ -257,11 +257,20 @@ static int luaB_assert (lua_State *L) {
257static int luaB_unpack (lua_State *L) { 257static int luaB_unpack (lua_State *L) {
258 int n, i; 258 int n, i;
259 luaL_check_type(L, 1, LUA_TTABLE); 259 luaL_check_type(L, 1, LUA_TTABLE);
260 n = lua_getn(L, 1); 260 lua_pushliteral(L, "n");
261 luaL_check_stack(L, n+LUA_MINSTACK, "table too big to unpack"); 261 lua_rawget(L, 1);
262 for (i=1; i<=n; i++) /* push arg[1...n] */ 262 n = (lua_isnumber(L, -1)) ? (int)lua_tonumber(L, -1) : -1;
263 lua_rawgeti(L, 1, i); 263 for (i=0; i<n || n==-1; i++) { /* push arg[1...n] */
264 return n; 264 luaL_check_stack(L, 1, "table too big to unpack");
265 lua_rawgeti(L, 1, i+1);
266 if (n == -1) { /* no explicit limit? */
267 if (lua_isnil(L, -1)) { /* stop at first `nil' element */
268 lua_pop(L, 1); /* remove `nil' */
269 break;
270 }
271 }
272 }
273 return i;
265} 274}
266 275
267 276