no more `lua_getn' function

This commit is contained in:
Roberto Ierusalimschy
2002-06-26 16:28:44 -03:00
parent cfcf200806
commit f67ccfbdeb
4 changed files with 27 additions and 53 deletions

39
lapi.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: lapi.c,v 1.202 2002/06/24 13:08:45 roberto Exp roberto $
** $Id: lapi.c,v 1.203 2002/06/25 19:15:41 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -697,43 +697,6 @@ LUA_API int lua_next (lua_State *L, int index) {
}
LUA_API int lua_getn (lua_State *L, int index) {
StkId t;
const TObject *value;
int n;
lua_lock(L);
t = luaA_index(L, index);
api_check(L, ttype(t) == LUA_TTABLE);
value = luaH_getstr(hvalue(t), luaS_newliteral(L, "n")); /* = t.n */
if (ttype(value) == LUA_TNUMBER)
lua_number2int(n, nvalue(value));
else {
Node *nd;
Table *a = hvalue(t);
lua_Number max = 0;
int i;
i = sizearray(a);
while (i--) {
if (ttype(&a->array[i]) != LUA_TNIL)
break;
}
max = i+1;
i = sizenode(a);
nd = a->node;
while (i--) {
if (ttype(key(nd)) == LUA_TNUMBER &&
ttype(val(nd)) != LUA_TNIL &&
nvalue(key(nd)) > max)
max = nvalue(key(nd));
nd++;
}
lua_number2int(n, max);
}
lua_unlock(L);
return n;
}
LUA_API void lua_concat (lua_State *L, int n) {
lua_lock(L);
api_checknelems(L, n);