mirror of
https://github.com/lua/lua
synced 2025-01-07 18:12:00 +03:00
new function `select'
This commit is contained in:
parent
0733c83b8c
commit
0f49b3e62d
16
lbaselib.c
16
lbaselib.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lbaselib.c,v 1.142 2004/04/30 20:13:38 roberto Exp roberto $
|
** $Id: lbaselib.c,v 1.143 2004/05/10 17:50:51 roberto Exp roberto $
|
||||||
** Basic library
|
** Basic library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -362,6 +362,19 @@ static int luaB_unpack (lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int luaB_select (lua_State *L) {
|
||||||
|
int i = luaL_checkint(L, 1);
|
||||||
|
int n = lua_gettop(L);
|
||||||
|
if (i < 0 || i >= n) /* index out of range? */
|
||||||
|
return 0;
|
||||||
|
if (i == 0)
|
||||||
|
lua_pushinteger(L, n-1);
|
||||||
|
else
|
||||||
|
lua_pushvalue(L, i+1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int luaB_pcall (lua_State *L) {
|
static int luaB_pcall (lua_State *L) {
|
||||||
int status;
|
int status;
|
||||||
luaL_checkany(L, 1);
|
luaL_checkany(L, 1);
|
||||||
@ -566,6 +579,7 @@ static const luaL_reg base_funcs[] = {
|
|||||||
{"type", luaB_type},
|
{"type", luaB_type},
|
||||||
{"assert", luaB_assert},
|
{"assert", luaB_assert},
|
||||||
{"unpack", luaB_unpack},
|
{"unpack", luaB_unpack},
|
||||||
|
{"select", luaB_select},
|
||||||
{"rawequal", luaB_rawequal},
|
{"rawequal", luaB_rawequal},
|
||||||
{"rawget", luaB_rawget},
|
{"rawget", luaB_rawget},
|
||||||
{"rawset", luaB_rawset},
|
{"rawset", luaB_rawset},
|
||||||
|
Loading…
Reference in New Issue
Block a user