From 57fb51f975c39a063896bccbf4b2e3169f309941 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 14 Feb 2002 19:46:13 -0200 Subject: `luaH_next' works like `next' --- lapi.c | 8 ++++---- ltable.h | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lapi.c b/lapi.c index bed22426..6f8037c5 100644 --- a/lapi.c +++ b/lapi.c @@ -567,18 +567,18 @@ LUA_API void lua_error (lua_State *L, const char *s) { LUA_API int lua_next (lua_State *L, int index) { StkId t; + int more; lua_lock(L); t = luaA_index(L, index); api_check(L, ttype(t) == LUA_TTABLE); - index = luaH_index(L, hvalue(t), luaA_index(L, -1)); - index = (luaH_nexti(hvalue(t), index, L->top - 1) != -1); - if (index) { + more = luaH_next(L, hvalue(t), L->top - 1); + if (more) { api_incr_top(L); } else /* no more elements */ L->top -= 1; /* remove key */ lua_unlock(L); - return index; + return more; } diff --git a/ltable.h b/ltable.h index 67199ad2..854f5344 100644 --- a/ltable.h +++ b/ltable.h @@ -24,8 +24,7 @@ const TObject *luaH_get (Table *t, const TObject *key); void luaH_set (lua_State *L, Table *t, const TObject *key, const TObject *val); Table *luaH_new (lua_State *L, int narray, int lnhash); void luaH_free (lua_State *L, Table *t); -int luaH_index (lua_State *L, Table *t, const TObject *key); -int luaH_nexti (Table *t, int i, TObject *where); +int luaH_next (lua_State *L, Table *t, TObject *key); /* exported only for debugging */ Node *luaH_mainposition (const Table *t, const TObject *key); -- cgit v1.2.3-55-g6feb