Browse Source

`luaH_next' works like `next'

Roberto Ierusalimschy 23 years ago
parent
commit
57fb51f975
2 changed files with 5 additions and 6 deletions
  1. 4 4
      lapi.c
  2. 1 2
      ltable.h

+ 4 - 4
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;
 }
 
 

+ 1 - 2
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);