summaryrefslogtreecommitdiff
path: root/ltablib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-07-02 13:01:44 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2011-07-02 13:01:44 -0300
commitee37ee50d6560dae4123396f47c505856f33a334 (patch)
tree105e3459974e1738d45f9e550a1d7a82ebc040b6 /ltablib.c
parentad1a54b5c0b045365326923ee4f3574773abefff (diff)
downloadlua-github-ee37ee50d6560dae4123396f47c505856f33a334.tar.gz
'table.pack' also returns 'n' + 'deprecated' changed to 'removed'
Diffstat (limited to 'ltablib.c')
-rw-r--r--ltablib.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/ltablib.c b/ltablib.c
index 64d13f2f..152135a7 100644
--- a/ltablib.c
+++ b/ltablib.c
@@ -1,5 +1,5 @@
/*
-** $Id: ltablib.c,v 1.58 2010/11/23 17:21:14 roberto Exp roberto $
+** $Id: ltablib.c,v 1.59 2010/12/17 12:15:34 roberto Exp roberto $
** Library for Table Manipulation
** See Copyright Notice in lua.h
*/
@@ -20,8 +20,8 @@
(luaL_checktype(L, n, LUA_TTABLE), luaL_len(L, n))
-static int deprecatedfunc (lua_State *L) {
- return luaL_error(L, "deprecated function");
+static int removedfunc (lua_State *L) {
+ return luaL_error(L, "removed function");
}
@@ -41,7 +41,7 @@ static int maxn (lua_State *L) {
return 1;
}
#else
-#define maxn deprecatedfunc
+#define maxn removedfunc
#endif
@@ -124,18 +124,20 @@ static int tconcat (lua_State *L) {
*/
static int pack (lua_State *L) {
- int top = lua_gettop(L);
- lua_createtable(L, top, 1); /* create result table */
- lua_pushinteger(L, top); /* number of elements */
+ int n = lua_gettop(L); /* number of elements to pack */
+ lua_createtable(L, n, 1); /* create result table */
+ lua_pushinteger(L, n);
lua_setfield(L, -2, "n"); /* t.n = number of elements */
- if (top > 0) { /* at least one element? */
+ if (n > 0) { /* at least one element? */
+ int i;
lua_pushvalue(L, 1);
lua_rawseti(L, -2, 1); /* insert first element */
- lua_replace(L, 1); /* move table into its position (index 1) */
- for (; top >= 2; top--) /* assign other elements */
- lua_rawseti(L, 1, top);
+ lua_replace(L, 1); /* move table into index 1 */
+ for (i = n; i >= 2; i--) /* assign other elements */
+ lua_rawseti(L, 1, i);
}
- return 1;
+ lua_pushinteger(L, n);
+ return 2; /* return table and number of elements */
}
@@ -265,9 +267,9 @@ static int sort (lua_State *L) {
static const luaL_Reg tab_funcs[] = {
{"concat", tconcat},
- {"foreach", deprecatedfunc},
- {"foreachi", deprecatedfunc},
- {"getn", deprecatedfunc},
+ {"foreach", removedfunc},
+ {"foreachi", removedfunc},
+ {"getn", removedfunc},
{"maxn", maxn},
{"insert", tinsert},
{"pack", pack},