lua

A copy of the Lua development repository
Log | Files | Refs | README

commit 57fb51f975c39a063896bccbf4b2e3169f309941
parent 1c423d266180a37fa00d433ec769b1420d591ba7
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Thu, 14 Feb 2002 19:45:51 -0200

`luaH_next' works like `next'

Diffstat:
Mlapi.c | 8++++----
Mltable.h | 3+--
2 files changed, 5 insertions(+), 6 deletions(-)

diff --git 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 @@ -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);