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