** 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. */
| 329 | ** beginning of a traversal is signaled by 0. |
| 330 | */ |
| 331 | static unsigned int findindex (lua_State *L, Table *t, TValue *key, |
| 332 | unsigned int asize) { |
| 333 | unsigned int i; |
| 334 | if (ttisnil(key)) return 0; /* first iteration */ |
| 335 | i = ttisinteger(key) ? arrayindex(ivalue(key)) : 0; |
| 336 | if (i - 1u < asize) /* is 'key' inside array part? */ |
| 337 | return i; /* yes; that's the index */ |
| 338 | else { |
| 339 | const TValue *n = getgeneric(t, key, 1); |
| 340 | if (l_unlikely(isabstkey(n))) |
| 341 | luaG_runerror(L, "invalid key to 'next'"); /* key not found */ |
| 342 | i = cast_int(nodefromval(n) - gnode(t, 0)); /* key index in hash table */ |
| 343 | /* hash elements are numbered after array ones */ |
| 344 | return (i + 1) + asize; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | |
| 349 | int luaH_next (lua_State *L, Table *t, StkId key) { |
no test coverage detected