From f04c83e0759b1059545ea0526c5999c35cb1793f Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 23 Feb 1999 11:57:28 -0300 Subject: new function "lua_next" (+ new implementation for "next") --- ltable.c | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'ltable.c') diff --git a/ltable.c b/ltable.c index 7b355519..85cc6218 100644 --- a/ltable.c +++ b/ltable.c @@ -1,5 +1,5 @@ /* -** $Id: ltable.c,v 1.19 1999/01/25 12:30:11 roberto Exp roberto $ +** $Id: ltable.c,v 1.20 1999/01/25 17:41:19 roberto Exp roberto $ ** Lua tables (hash) ** See Copyright Notice in lua.h */ @@ -152,28 +152,10 @@ void luaH_set (Hash *t, TObject *ref, TObject *val) { } -static Node *hashnext (Hash *t, int i) { - Node *n; - int tsize = nhash(t); - if (i >= tsize) - return NULL; - n = node(t, i); - while (ttype(val(n)) == LUA_T_NIL) { - if (++i >= tsize) - return NULL; - n = node(t, i); - } - return n; -} - -Node *luaH_next (Hash *t, TObject *r) { - if (ttype(r) == LUA_T_NIL) - return hashnext(t, 0); - else { - Node *n = luaH_present(t, r); - luaL_arg_check(ttype(val(n)) != LUA_T_NIL, 2, "key not found"); - return hashnext(t, (n-(t->node))+1); - } +int luaH_pos (Hash *t, TObject *r) { + Node *n = luaH_present(t, r); + luaL_arg_check(ttype(val(n)) != LUA_T_NIL, 2, "key not found"); + return n-(t->node); } -- cgit v1.2.3-55-g6feb