luaH_next' works like next'

This commit is contained in:
Roberto Ierusalimschy 2002-02-14 19:46:13 -02:00
parent 1c423d2661
commit 57fb51f975
2 changed files with 5 additions and 6 deletions

8
lapi.c
View file

@ -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;
}

View file

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