** 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. */
| 285 | ** beginning of a traversal is signaled by 0. |
| 286 | */ |
| 287 | static unsigned int findindex (lua_State *L, Table *t, TValue *key, |
| 288 | unsigned int asize) { |
| 289 | unsigned int i; |
| 290 | if (ttisnil(key)) return 0; /* first iteration */ |
| 291 | i = ttisinteger(key) ? arrayindex(ivalue(key)) : 0; |
| 292 | if (i - 1u < asize) /* is 'key' inside array part? */ |
| 293 | return i; /* yes; that's the index */ |
| 294 | else { |
| 295 | const TValue *n = getgeneric(t, key); |
| 296 | if (unlikely(isabstkey(n))) |
| 297 | luaG_runerror(L, "invalid key to 'next'"); /* key not found */ |
| 298 | i = cast_int(nodefromval(n) - gnode(t, 0)); /* key index in hash table */ |
| 299 | /* hash elements are numbered after array ones */ |
| 300 | return (i + 1) + asize; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | |
| 305 | int luaH_next (lua_State *L, Table *t, StkId key) { |
no test coverage detected