From ade585bdf9e286a0ec01796763ded6701c6b1a8f Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 28 Mar 2005 14:17:53 -0300 Subject: no more LUA_FIRSTINDEX --- ltablib.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'ltablib.c') diff --git a/ltablib.c b/ltablib.c index 42575685..30220300 100644 --- a/ltablib.c +++ b/ltablib.c @@ -1,5 +1,5 @@ /* -** $Id: ltablib.c,v 1.27 2004/12/07 18:28:47 roberto Exp roberto $ +** $Id: ltablib.c,v 1.28 2005/03/16 16:58:41 roberto Exp roberto $ ** Library for Table Manipulation ** See Copyright Notice in lua.h */ @@ -23,7 +23,7 @@ static int foreachi (lua_State *L) { int i; int n = aux_getn(L, 1); luaL_checktype(L, 2, LUA_TFUNCTION); - for (i=LUA_FIRSTINDEX; i < n+LUA_FIRSTINDEX; i++) { + for (i=1; i <= n; i++) { lua_pushvalue(L, 2); /* function */ lua_pushinteger(L, i); /* 1st argument */ lua_rawgeti(L, 1, i); /* 2nd argument */ @@ -73,7 +73,7 @@ static int setn (lua_State *L) { static int tinsert (lua_State *L) { - int e = aux_getn(L, 1) + LUA_FIRSTINDEX; /* first empty element */ + int e = aux_getn(L, 1) + 1; /* first empty element */ int pos; /* where to insert new element */ if (lua_isnone(L, 3)) /* called with only 2 arguments */ pos = e; /* insert new element at the end */ @@ -87,17 +87,17 @@ static int tinsert (lua_State *L) { lua_rawseti(L, 1, i); /* t[i] = t[i-1] */ } } - luaL_setn(L, 1, e - LUA_FIRSTINDEX + 1); /* new size */ + luaL_setn(L, 1, e); /* new size */ lua_rawseti(L, 1, pos); /* t[pos] = v */ return 0; } static int tremove (lua_State *L) { - int e = aux_getn(L, 1) + LUA_FIRSTINDEX - 1; + int e = aux_getn(L, 1); int pos = luaL_optint(L, 2, e); - if (e < LUA_FIRSTINDEX) return 0; /* table is `empty' */ - luaL_setn(L, 1, e - LUA_FIRSTINDEX); /* t.n = n-1 */ + if (e == 0) return 0; /* table is `empty' */ + luaL_setn(L, 1, e - 1); /* t.n = n-1 */ lua_rawgeti(L, 1, pos); /* result = t[pos] */ for ( ;pos