MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / findindex

Function findindex

xrepo/packages/l/lua/port/lua/src/ltable.c:329–344  ·  view source on GitHub ↗

** 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. */

Source from the content-addressed store, hash-verified

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

Callers 1

luaH_nextFunction · 0.70

Calls 3

getgenericFunction · 0.85
luaG_runerrorFunction · 0.85
arrayindexFunction · 0.70

Tested by

no test coverage detected