diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-05-10 14:50:51 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-05-10 14:50:51 -0300 |
| commit | 7e41612eb28ff0fba282bd419781fcbc9bd94776 (patch) | |
| tree | e63123d15589435c08c844b0d471b142c924818b /lbaselib.c | |
| parent | b0f341ee52ee7d3d22261a68caf06eab5b0c8822 (diff) | |
| download | lua-7e41612eb28ff0fba282bd419781fcbc9bd94776.tar.gz lua-7e41612eb28ff0fba282bd419781fcbc9bd94776.tar.bz2 lua-7e41612eb28ff0fba282bd419781fcbc9bd94776.zip | |
code parameterized by LUA_FIRSTINDEX (first index of an array)
Diffstat (limited to 'lbaselib.c')
| -rw-r--r-- | lbaselib.c | 9 |
1 files changed, 5 insertions, 4 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.141 2004/03/26 13:25:17 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.142 2004/04/30 20:13:38 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,7 +257,7 @@ static int luaB_ipairs (lua_State *L) { | |||
| 257 | luaL_checktype(L, 1, LUA_TTABLE); | 257 | luaL_checktype(L, 1, LUA_TTABLE); |
| 258 | lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ | 258 | lua_pushvalue(L, lua_upvalueindex(1)); /* return generator, */ |
| 259 | lua_pushvalue(L, 1); /* state, */ | 259 | lua_pushvalue(L, 1); /* state, */ |
| 260 | lua_pushinteger(L, 0); /* and initial value */ | 260 | lua_pushinteger(L, LUA_FIRSTINDEX - 1); /* and initial value */ |
| 261 | return 3; | 261 | return 3; |
| 262 | } | 262 | } |
| 263 | 263 | ||
| @@ -347,11 +347,12 @@ static int luaB_assert (lua_State *L) { | |||
| 347 | 347 | ||
| 348 | 348 | ||
| 349 | static int luaB_unpack (lua_State *L) { | 349 | static int luaB_unpack (lua_State *L) { |
| 350 | int i = luaL_optint(L, 2, 1); | 350 | int i = luaL_optint(L, 2, LUA_FIRSTINDEX); |
| 351 | int e = luaL_optint(L, 3, -1); | 351 | int e = luaL_optint(L, 3, -1); |
| 352 | int n; | 352 | int n; |
| 353 | luaL_checktype(L, 1, LUA_TTABLE); | 353 | luaL_checktype(L, 1, LUA_TTABLE); |
| 354 | if (e == -1) e = luaL_getn(L, 1); | 354 | if (e == -1) |
| 355 | e = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1; | ||
| 355 | n = e - i + 1; /* number of elements */ | 356 | n = e - i + 1; /* number of elements */ |
| 356 | if (n <= 0) return 0; /* empty range */ | 357 | if (n <= 0) return 0; /* empty range */ |
| 357 | luaL_checkstack(L, n, "table too big to unpack"); | 358 | luaL_checkstack(L, n, "table too big to unpack"); |
