aboutsummaryrefslogtreecommitdiff
path: root/ltablib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-03-28 14:17:53 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-03-28 14:17:53 -0300
commitade585bdf9e286a0ec01796763ded6701c6b1a8f (patch)
treea578c006fc70e54114e1056bbbf8a014ccc30721 /ltablib.c
parent04c41444e22740119d3c017830276d6590b09747 (diff)
downloadlua-ade585bdf9e286a0ec01796763ded6701c6b1a8f.tar.gz
lua-ade585bdf9e286a0ec01796763ded6701c6b1a8f.tar.bz2
lua-ade585bdf9e286a0ec01796763ded6701c6b1a8f.zip
no more LUA_FIRSTINDEX
Diffstat (limited to 'ltablib.c')
-rw-r--r--ltablib.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/ltablib.c b/ltablib.c
index 42575685..30220300 100644
--- a/ltablib.c
+++ b/ltablib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltablib.c,v 1.27 2004/12/07 18:28:47 roberto Exp roberto $ 2** $Id: ltablib.c,v 1.28 2005/03/16 16:58:41 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*/
@@ -23,7 +23,7 @@ static int foreachi (lua_State *L) {
23 int i; 23 int i;
24 int n = aux_getn(L, 1); 24 int n = aux_getn(L, 1);
25 luaL_checktype(L, 2, LUA_TFUNCTION); 25 luaL_checktype(L, 2, LUA_TFUNCTION);
26 for (i=LUA_FIRSTINDEX; i < n+LUA_FIRSTINDEX; i++) { 26 for (i=1; i <= n; i++) {
27 lua_pushvalue(L, 2); /* function */ 27 lua_pushvalue(L, 2); /* function */
28 lua_pushinteger(L, i); /* 1st argument */ 28 lua_pushinteger(L, i); /* 1st argument */
29 lua_rawgeti(L, 1, i); /* 2nd argument */ 29 lua_rawgeti(L, 1, i); /* 2nd argument */
@@ -73,7 +73,7 @@ static int setn (lua_State *L) {
73 73
74 74
75static int tinsert (lua_State *L) { 75static int tinsert (lua_State *L) {
76 int e = aux_getn(L, 1) + LUA_FIRSTINDEX; /* first empty element */ 76 int e = aux_getn(L, 1) + 1; /* first empty element */
77 int pos; /* where to insert new element */ 77 int pos; /* where to insert new element */
78 if (lua_isnone(L, 3)) /* called with only 2 arguments */ 78 if (lua_isnone(L, 3)) /* called with only 2 arguments */
79 pos = e; /* insert new element at the end */ 79 pos = e; /* insert new element at the end */
@@ -87,17 +87,17 @@ static int tinsert (lua_State *L) {
87 lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ 87 lua_rawseti(L, 1, i); /* t[i] = t[i-1] */
88 } 88 }
89 } 89 }
90 luaL_setn(L, 1, e - LUA_FIRSTINDEX + 1); /* new size */ 90 luaL_setn(L, 1, e); /* new size */
91 lua_rawseti(L, 1, pos); /* t[pos] = v */ 91 lua_rawseti(L, 1, pos); /* t[pos] = v */
92 return 0; 92 return 0;
93} 93}
94 94
95 95
96static int tremove (lua_State *L) { 96static int tremove (lua_State *L) {
97 int e = aux_getn(L, 1) + LUA_FIRSTINDEX - 1; 97 int e = aux_getn(L, 1);
98 int pos = luaL_optint(L, 2, e); 98 int pos = luaL_optint(L, 2, e);
99 if (e < LUA_FIRSTINDEX) return 0; /* table is `empty' */ 99 if (e == 0) return 0; /* table is `empty' */
100 luaL_setn(L, 1, e - LUA_FIRSTINDEX); /* t.n = n-1 */ 100 luaL_setn(L, 1, e - 1); /* t.n = n-1 */
101 lua_rawgeti(L, 1, pos); /* result = t[pos] */ 101 lua_rawgeti(L, 1, pos); /* result = t[pos] */
102 for ( ;pos<e; pos++) { 102 for ( ;pos<e; pos++) {
103 lua_rawgeti(L, 1, pos+1); 103 lua_rawgeti(L, 1, pos+1);
@@ -113,11 +113,11 @@ static int str_concat (lua_State *L) {
113 luaL_Buffer b; 113 luaL_Buffer b;
114 size_t lsep; 114 size_t lsep;
115 const char *sep = luaL_optlstring(L, 2, "", &lsep); 115 const char *sep = luaL_optlstring(L, 2, "", &lsep);
116 int i = luaL_optint(L, 3, LUA_FIRSTINDEX); 116 int i = luaL_optint(L, 3, 1);
117 int last = luaL_optint(L, 4, -2); 117 int last = luaL_optint(L, 4, -2);
118 luaL_checktype(L, 1, LUA_TTABLE); 118 luaL_checktype(L, 1, LUA_TTABLE);
119 if (last == -2) 119 if (last == -2)
120 last = luaL_getn(L, 1) + LUA_FIRSTINDEX - 1; 120 last = luaL_getn(L, 1);
121 luaL_buffinit(L, &b); 121 luaL_buffinit(L, &b);
122 for (; i <= last; i++) { 122 for (; i <= last; i++) {
123 lua_rawgeti(L, 1, i); 123 lua_rawgeti(L, 1, i);
@@ -229,7 +229,7 @@ static int sort (lua_State *L) {
229 if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */ 229 if (!lua_isnoneornil(L, 2)) /* is there a 2nd argument? */
230 luaL_checktype(L, 2, LUA_TFUNCTION); 230 luaL_checktype(L, 2, LUA_TFUNCTION);
231 lua_settop(L, 2); /* make sure there is two arguments */ 231 lua_settop(L, 2); /* make sure there is two arguments */
232 auxsort(L, LUA_FIRSTINDEX, n + LUA_FIRSTINDEX - 1); 232 auxsort(L, 1, n);
233 return 0; 233 return 0;
234} 234}
235 235