mirror of https://github.com/rusefi/lua.git
removed deprecated functions getn-foreach-foreachi
This commit is contained in:
parent
a64cf8fac9
commit
5b33e39855
60
ltablib.c
60
ltablib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ltablib.c,v 1.56 2010/07/02 11:38:13 roberto Exp roberto $
|
** $Id: ltablib.c,v 1.57 2010/10/25 19:01:37 roberto Exp roberto $
|
||||||
** Library for Table Manipulation
|
** Library for Table Manipulation
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -20,47 +20,8 @@
|
||||||
(luaL_checktype(L, n, LUA_TTABLE), (int)lua_rawlen(L, n))
|
(luaL_checktype(L, n, LUA_TTABLE), (int)lua_rawlen(L, n))
|
||||||
|
|
||||||
|
|
||||||
static int foreachi (lua_State *L) {
|
static int deprecatedfunc (lua_State *L) {
|
||||||
int n = aux_getn(L, 1);
|
return luaL_error(L, "deprecated function");
|
||||||
int i;
|
|
||||||
if (lua_getctx(L, &i) == LUA_YIELD) goto poscall;
|
|
||||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
|
||||||
for (i = 1; i <= n; i++) {
|
|
||||||
lua_pushvalue(L, 2); /* function */
|
|
||||||
lua_pushinteger(L, i); /* 1st argument */
|
|
||||||
lua_rawgeti(L, 1, i); /* 2nd argument */
|
|
||||||
lua_callk(L, 2, 1, i, foreachi);
|
|
||||||
poscall:
|
|
||||||
if (!lua_isnil(L, -1))
|
|
||||||
return 1;
|
|
||||||
lua_pop(L, 1); /* remove nil result */
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int foreachcont (lua_State *L) {
|
|
||||||
for (;;) {
|
|
||||||
if (!lua_isnil(L, -1))
|
|
||||||
return 1;
|
|
||||||
lua_pop(L, 2); /* remove value and result */
|
|
||||||
if (lua_next(L, 1) == 0) /* no more elements? */
|
|
||||||
return 0;
|
|
||||||
lua_pushvalue(L, 2); /* function */
|
|
||||||
lua_pushvalue(L, -3); /* key */
|
|
||||||
lua_pushvalue(L, -3); /* value */
|
|
||||||
lua_callk(L, 2, 1, 0, foreachcont);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int foreach (lua_State *L) {
|
|
||||||
luaL_checktype(L, 1, LUA_TTABLE);
|
|
||||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
|
||||||
lua_pushnil(L); /* first key */
|
|
||||||
lua_pushnil(L); /* first value */
|
|
||||||
lua_pushnil(L); /* first "return" */
|
|
||||||
return foreachcont(L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,16 +41,9 @@ static int maxn (lua_State *L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static int maxn (lua_State *L) {
|
#define maxn deprecatedfunc
|
||||||
return luaL_error(L, "function 'maxn' is deprecated");
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int getn (lua_State *L) {
|
|
||||||
lua_pushinteger(L, aux_getn(L, 1));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int tinsert (lua_State *L) {
|
static int tinsert (lua_State *L) {
|
||||||
int e = aux_getn(L, 1) + 1; /* first empty element */
|
int e = aux_getn(L, 1) + 1; /* first empty element */
|
||||||
|
@ -311,9 +265,9 @@ static int sort (lua_State *L) {
|
||||||
|
|
||||||
static const luaL_Reg tab_funcs[] = {
|
static const luaL_Reg tab_funcs[] = {
|
||||||
{"concat", tconcat},
|
{"concat", tconcat},
|
||||||
{"foreach", foreach},
|
{"foreach", deprecatedfunc},
|
||||||
{"foreachi", foreachi},
|
{"foreachi", deprecatedfunc},
|
||||||
{"getn", getn},
|
{"getn", deprecatedfunc},
|
||||||
{"maxn", maxn},
|
{"maxn", maxn},
|
||||||
{"insert", tinsert},
|
{"insert", tinsert},
|
||||||
{"pack", pack},
|
{"pack", pack},
|
||||||
|
|
Loading…
Reference in New Issue