summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-11-23 15:21:14 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-11-23 15:21:14 -0200
commit5b33e398557d7afad4a916bb483e9894e4b9b3d4 (patch)
tree8bd6479713c634faf882948f6e027a418d327692
parenta64cf8fac97d59ae782625fa1aedae3b5f3331d4 (diff)
downloadlua-5.2-alpha.tar.gz
lua-5.2-alpha.tar.bz2
lua-5.2-alpha.zip
removed deprecated functions getn-foreach-foreachiv5.2-alpha
-rw-r--r--ltablib.c60
1 files changed, 7 insertions, 53 deletions
diff --git a/ltablib.c b/ltablib.c
index 9aa7d5c9..f1fb9cdd 100644
--- a/ltablib.c
+++ b/ltablib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltablib.c,v 1.56 2010/07/02 11:38:13 roberto Exp roberto $ 2** $Id: ltablib.c,v 1.57 2010/10/25 19:01:37 roberto Exp roberto $
3** Library for Table Manipulation 3** Library for Table Manipulation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -20,47 +20,8 @@
20 (luaL_checktype(L, n, LUA_TTABLE), (int)lua_rawlen(L, n)) 20 (luaL_checktype(L, n, LUA_TTABLE), (int)lua_rawlen(L, n))
21 21
22 22
23static int foreachi (lua_State *L) { 23static int deprecatedfunc (lua_State *L) {
24 int n = aux_getn(L, 1); 24 return luaL_error(L, "deprecated function");
25 int i;
26 if (lua_getctx(L, &i) == LUA_YIELD) goto poscall;
27 luaL_checktype(L, 2, LUA_TFUNCTION);
28 for (i = 1; i <= n; i++) {
29 lua_pushvalue(L, 2); /* function */
30 lua_pushinteger(L, i); /* 1st argument */
31 lua_rawgeti(L, 1, i); /* 2nd argument */
32 lua_callk(L, 2, 1, i, foreachi);
33 poscall:
34 if (!lua_isnil(L, -1))
35 return 1;
36 lua_pop(L, 1); /* remove nil result */
37 }
38 return 0;
39}
40
41
42static int foreachcont (lua_State *L) {
43 for (;;) {
44 if (!lua_isnil(L, -1))
45 return 1;
46 lua_pop(L, 2); /* remove value and result */
47 if (lua_next(L, 1) == 0) /* no more elements? */
48 return 0;
49 lua_pushvalue(L, 2); /* function */
50 lua_pushvalue(L, -3); /* key */
51 lua_pushvalue(L, -3); /* value */
52 lua_callk(L, 2, 1, 0, foreachcont);
53 }
54}
55
56
57static int foreach (lua_State *L) {
58 luaL_checktype(L, 1, LUA_TTABLE);
59 luaL_checktype(L, 2, LUA_TFUNCTION);
60 lua_pushnil(L); /* first key */
61 lua_pushnil(L); /* first value */
62 lua_pushnil(L); /* first "return" */
63 return foreachcont(L);
64} 25}
65 26
66 27
@@ -80,16 +41,9 @@ static int maxn (lua_State *L) {
80 return 1; 41 return 1;
81} 42}
82#else 43#else
83static int maxn (lua_State *L) { 44#define maxn deprecatedfunc
84 return luaL_error(L, "function 'maxn' is deprecated");
85}
86#endif 45#endif
87 46
88static int getn (lua_State *L) {
89 lua_pushinteger(L, aux_getn(L, 1));
90 return 1;
91}
92
93 47
94static int tinsert (lua_State *L) { 48static int tinsert (lua_State *L) {
95 int e = aux_getn(L, 1) + 1; /* first empty element */ 49 int e = aux_getn(L, 1) + 1; /* first empty element */
@@ -311,9 +265,9 @@ static int sort (lua_State *L) {
311 265
312static const luaL_Reg tab_funcs[] = { 266static const luaL_Reg tab_funcs[] = {
313 {"concat", tconcat}, 267 {"concat", tconcat},
314 {"foreach", foreach}, 268 {"foreach", deprecatedfunc},
315 {"foreachi", foreachi}, 269 {"foreachi", deprecatedfunc},
316 {"getn", getn}, 270 {"getn", deprecatedfunc},
317 {"maxn", maxn}, 271 {"maxn", maxn},
318 {"insert", tinsert}, 272 {"insert", tinsert},
319 {"pack", pack}, 273 {"pack", pack},