** 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 -1. */
| 142 | ** beginning of a traversal is signaled by -1. |
| 143 | */ |
| 144 | static int findindex (lua_State *L, Table *t, StkId key) { |
| 145 | int i; |
| 146 | if (ttisnil(key)) return -1; /* first iteration */ |
| 147 | i = arrayindex(key); |
| 148 | if (0 < i && i <= t->sizearray) /* is `key' inside array part? */ |
| 149 | return i-1; /* yes; that's the index (corrected to C) */ |
| 150 | else { |
| 151 | Node *n = mainposition(t, key); |
| 152 | for (;;) { /* check whether `key' is somewhere in the chain */ |
| 153 | /* key may be dead already, but it is ok to use it in `next' */ |
| 154 | if (luaV_rawequalobj(gkey(n), key) || |
| 155 | (ttisdeadkey(gkey(n)) && iscollectable(key) && |
| 156 | deadvalue(gkey(n)) == gcvalue(key))) { |
| 157 | i = cast_int(n - gnode(t, 0)); /* key index in hash table */ |
| 158 | /* hash elements are numbered after array ones */ |
| 159 | return i + t->sizearray; |
| 160 | } |
| 161 | else n = gnext(n); |
| 162 | if (n == NULL) |
| 163 | luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */ |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | |
| 169 | int luaH_next (lua_State *L, Table *t, StkId key) { |
no test coverage detected