Просмотр исходного кода

bug: `next' did not work for numeric indices

Roberto Ierusalimschy 24 лет назад
Родитель
Сommit
657f65211a
2 измененных файлов с 7 добавлено и 8 удалено
  1. 5 6
      lapi.c
  2. 2 2
      ltable.c

+ 5 - 6
lapi.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lapi.c,v 1.158 2001/10/31 19:40:14 roberto Exp roberto $
+** $Id: lapi.c,v 1.159 2001/10/31 19:58:11 roberto Exp $
 ** Lua API
 ** See Copyright Notice in lua.h
 */
@@ -608,19 +608,18 @@ LUA_API void lua_error (lua_State *L, const l_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);
-  more = luaH_index(L, hvalue(t), luaA_index(L, -1));
-  more = (luaH_nexti(hvalue(t), more, L->top - 1) != -1);
-  if (more) {
+  index = luaH_index(L, hvalue(t), luaA_index(L, -1));
+  index = (luaH_nexti(hvalue(t), index, L->top - 1) != -1);
+  if (index) {
     api_incr_top(L);
   }
   else  /* no more elements */
     L->top -= 1;  /* remove key */
   lua_unlock(L);
-  return more;
+  return index;
 }
 
 

+ 2 - 2
ltable.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltable.c,v 1.86 2001/09/07 17:30:16 roberto Exp $
+** $Id: ltable.c,v 1.87 2001/10/25 19:14:14 roberto Exp $
 ** Lua tables (hash)
 ** See Copyright Notice in lua.h
 */
@@ -96,7 +96,7 @@ int luaH_index (lua_State *L, Table *t, const TObject *key) {
   if (ttype(key) == LUA_TNIL) return -1;  /* first iteration */
   i = arrayindex(key);
   if (0 <= i && i < t->sizearray) {  /* is `key' inside array part? */
-    return i;  /* yes; that's the index */
+    return i-1;  /* yes; that's the index (corrected to C) */
   }
   else {
     const TObject *v = luaH_get(t, key);