diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-26 16:28:44 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-06-26 16:28:44 -0300 |
| commit | f67ccfbdeb9595b0549a733d229a02a7c3205ddc (patch) | |
| tree | b59a5afc174ac338e23ad58dc564640324ba6b19 /lbaselib.c | |
| parent | cfcf2008069fc2d5574e10303dbe4f1ea3188636 (diff) | |
| download | lua-f67ccfbdeb9595b0549a733d229a02a7c3205ddc.tar.gz lua-f67ccfbdeb9595b0549a733d229a02a7c3205ddc.tar.bz2 lua-f67ccfbdeb9595b0549a733d229a02a7c3205ddc.zip | |
no more `lua_getn' function
Diffstat (limited to 'lbaselib.c')
| -rw-r--r-- | lbaselib.c | 21 |
1 files changed, 15 insertions, 6 deletions
| @@ -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) { | |||
| 257 | static int luaB_unpack (lua_State *L) { | 257 | static 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 | ||
