diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-08-30 12:28:32 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-08-30 12:28:32 -0300 |
commit | bcb2cb59ac235297e6ef8153ffd414836ae38efd (patch) | |
tree | 6dacb6f8a4cd7d9243ae1da4fda7a0df6303aee0 /lbaselib.c | |
parent | 0b062414831e3794fcdb747e53e9662d112473cf (diff) | |
download | lua-bcb2cb59ac235297e6ef8153ffd414836ae38efd.tar.gz lua-bcb2cb59ac235297e6ef8153ffd414836ae38efd.tar.bz2 lua-bcb2cb59ac235297e6ef8153ffd414836ae38efd.zip |
`select' returns all values after given `n'
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.153 2004/07/09 16:01:38 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.154 2004/07/09 18:23:17 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 | */ |
@@ -348,15 +348,17 @@ static int luaB_unpack (lua_State *L) { | |||
348 | 348 | ||
349 | 349 | ||
350 | static int luaB_select (lua_State *L) { | 350 | static int luaB_select (lua_State *L) { |
351 | int i = luaL_checkint(L, 1); | ||
352 | int n = lua_gettop(L); | 351 | int n = lua_gettop(L); |
353 | if (i < 0 || i >= n) /* index out of range? */ | 352 | if (lua_type(L, 1) == LUA_TSTRING && *lua_tostring(L, 1) == '#') { |
354 | return 0; | ||
355 | if (i == 0) | ||
356 | lua_pushinteger(L, n-1); | 353 | lua_pushinteger(L, n-1); |
357 | else | 354 | return 1; |
358 | lua_pushvalue(L, i+1); | 355 | } |
359 | return 1; | 356 | else { |
357 | int i = luaL_checkint(L, 1); | ||
358 | if (i <= 0) i = 1; | ||
359 | else if (i >= n) i = n; | ||
360 | return n - i; | ||
361 | } | ||
360 | } | 362 | } |
361 | 363 | ||
362 | 364 | ||