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