** 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 signalled by -1. */
| 169 | ** beginning of a traversal is signalled by -1. |
| 170 | */ |
| 171 | static int findindex (lua_State *L, Table *t, StkId key) { |
| 172 | int i; |
| 173 | if (ttisnil(key)) return -1; /* first iteration */ |
| 174 | i = arrayindex(key); |
| 175 | if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ |
| 176 | return i-1; /* yes; that's the index (corrected to C) */ |
| 177 | else { |
| 178 | Node *n = mainposition(t, key); |
| 179 | do { /* check whether `key' is somewhere in the chain */ |
| 180 | /* key may be dead already, but it is ok to use it in `next' */ |
| 181 | if (luaO_rawequalObj(key2tval(n), key) || |
| 182 | (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) && |
| 183 | gcvalue(gkey(n)) == gcvalue(key))) { |
| 184 | i = cast_int(n - gnode(t, 0)); /* key index in hash table */ |
| 185 | /* hash elements are numbered after array ones */ |
| 186 | return i + t->sizearray; |
| 187 | } |
| 188 | else n = gnext(n); |
| 189 | } while (n); |
| 190 | luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */ |
| 191 | return 0; /* to avoid warnings */ |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | |
| 196 | int luaH_next (lua_State *L, Table *t, StkId key) { |
no test coverage detected