diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-05-31 15:50:30 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-05-31 15:50:30 -0300 |
commit | 0f49b3e62dbfb4997dc49d2a19d22fd65d8d8772 (patch) | |
tree | 1cdc27fff194df84fe0ad57b464d852e0d468840 /lbaselib.c | |
parent | 0733c83b8ce08234aa4b9b4889bae029dcfb8414 (diff) | |
download | lua-0f49b3e62dbfb4997dc49d2a19d22fd65d8d8772.tar.gz lua-0f49b3e62dbfb4997dc49d2a19d22fd65d8d8772.tar.bz2 lua-0f49b3e62dbfb4997dc49d2a19d22fd65d8d8772.zip |
new function `select'
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.142 2004/04/30 20:13:38 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.143 2004/05/10 17:50:51 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 | */ |
@@ -362,6 +362,19 @@ static int luaB_unpack (lua_State *L) { | |||
362 | } | 362 | } |
363 | 363 | ||
364 | 364 | ||
365 | static int luaB_select (lua_State *L) { | ||
366 | int i = luaL_checkint(L, 1); | ||
367 | int n = lua_gettop(L); | ||
368 | if (i < 0 || i >= n) /* index out of range? */ | ||
369 | return 0; | ||
370 | if (i == 0) | ||
371 | lua_pushinteger(L, n-1); | ||
372 | else | ||
373 | lua_pushvalue(L, i+1); | ||
374 | return 1; | ||
375 | } | ||
376 | |||
377 | |||
365 | static int luaB_pcall (lua_State *L) { | 378 | static int luaB_pcall (lua_State *L) { |
366 | int status; | 379 | int status; |
367 | luaL_checkany(L, 1); | 380 | luaL_checkany(L, 1); |
@@ -566,6 +579,7 @@ static const luaL_reg base_funcs[] = { | |||
566 | {"type", luaB_type}, | 579 | {"type", luaB_type}, |
567 | {"assert", luaB_assert}, | 580 | {"assert", luaB_assert}, |
568 | {"unpack", luaB_unpack}, | 581 | {"unpack", luaB_unpack}, |
582 | {"select", luaB_select}, | ||
569 | {"rawequal", luaB_rawequal}, | 583 | {"rawequal", luaB_rawequal}, |
570 | {"rawget", luaB_rawget}, | 584 | {"rawget", luaB_rawget}, |
571 | {"rawset", luaB_rawset}, | 585 | {"rawset", luaB_rawset}, |