code parameterized by LUA_FIRSTINDEX (first index of an array)

This commit is contained in:
Roberto Ierusalimschy
2004-05-10 14:50:51 -03:00
parent b0f341ee52
commit 7e41612eb2
7 changed files with 32 additions and 25 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.110 2004/03/23 16:38:43 roberto Exp roberto $
** $Id: lauxlib.c,v 1.111 2004/04/30 20:13:38 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -308,13 +308,13 @@ LUALIB_API int luaL_getn (lua_State *L, int t) {
if ((n = checkint(L, 2)) >= 0) return n;
lua_getfield(L, t, "n"); /* else try t.n */
if ((n = checkint(L, 1)) >= 0) return n;
for (n = 1; ; n++) { /* else must count elements */
for (n = LUA_FIRSTINDEX; ; n++) { /* else must count elements */
lua_rawgeti(L, t, n);
if (lua_isnil(L, -1)) break;
lua_pop(L, 1);
}
lua_pop(L, 1);
return n - 1;
return n - LUA_FIRSTINDEX;
}
/* }====================================================== */