aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-02-14 19:46:13 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-02-14 19:46:13 -0200
commit57fb51f975c39a063896bccbf4b2e3169f309941 (patch)
treef641bb2984a03f48cdb67b2815a03ebfc393d8db
parent1c423d266180a37fa00d433ec769b1420d591ba7 (diff)
downloadlua-57fb51f975c39a063896bccbf4b2e3169f309941.tar.gz
lua-57fb51f975c39a063896bccbf4b2e3169f309941.tar.bz2
lua-57fb51f975c39a063896bccbf4b2e3169f309941.zip
`luaH_next' works like `next'
-rw-r--r--lapi.c8
-rw-r--r--ltable.h3
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) {
567 567
568LUA_API int lua_next (lua_State *L, int index) { 568LUA_API int lua_next (lua_State *L, int index) {
569 StkId t; 569 StkId t;
570 int more;
570 lua_lock(L); 571 lua_lock(L);
571 t = luaA_index(L, index); 572 t = luaA_index(L, index);
572 api_check(L, ttype(t) == LUA_TTABLE); 573 api_check(L, ttype(t) == LUA_TTABLE);
573 index = luaH_index(L, hvalue(t), luaA_index(L, -1)); 574 more = luaH_next(L, hvalue(t), L->top - 1);
574 index = (luaH_nexti(hvalue(t), index, L->top - 1) != -1); 575 if (more) {
575 if (index) {
576 api_incr_top(L); 576 api_incr_top(L);
577 } 577 }
578 else /* no more elements */ 578 else /* no more elements */
579 L->top -= 1; /* remove key */ 579 L->top -= 1; /* remove key */
580 lua_unlock(L); 580 lua_unlock(L);
581 return index; 581 return more;
582} 582}
583 583
584 584
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);
24void luaH_set (lua_State *L, Table *t, const TObject *key, const TObject *val); 24void luaH_set (lua_State *L, Table *t, const TObject *key, const TObject *val);
25Table *luaH_new (lua_State *L, int narray, int lnhash); 25Table *luaH_new (lua_State *L, int narray, int lnhash);
26void luaH_free (lua_State *L, Table *t); 26void luaH_free (lua_State *L, Table *t);
27int luaH_index (lua_State *L, Table *t, const TObject *key); 27int luaH_next (lua_State *L, Table *t, TObject *key);
28int luaH_nexti (Table *t, int i, TObject *where);
29 28
30/* exported only for debugging */ 29/* exported only for debugging */
31Node *luaH_mainposition (const Table *t, const TObject *key); 30Node *luaH_mainposition (const Table *t, const TObject *key);