/* returns the index of a 'key' for table traversals. First goes all elements in the array part, then elements in the hash part. The beginning of a traversal is signaled by 0.  */
static unsigned int findindex(lua_State *L, Table *t, StkId key)
/* returns the index of a 'key' for table traversals. First goes all elements in the array part, then elements in the hash part. The beginning of a traversal is signaled by 0.  */
static unsigned int findindex(lua_State *L, Table *t, StkId key)
{
    int nx;
    Node *n = mainposition(t, key);
    for (;;) {
      if (luaV_rawequalobj(gkey(n), key) ||
            (ttisdeadkey(gkey(n)) && iscollectable(key) &&
             deadvalue(gkey(n)) == gcvalue(key))) {
        i = cast_int(n - gnode(t, 0));
        return (i + 1) + t->sizearray;
      }
      nx = gnext(n);
      if (nx == 0)
        luaG_runerror(L, "invalid key to 'next'");
      else n += nx;
    }
  }
}