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

Function findindex

extlibs/lua/src/ltable.c:287–302  ·  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

285** beginning of a traversal is signaled by 0.
286*/
287static 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
305int luaH_next (lua_State *L, Table *t, StkId key) {

Callers 1

luaH_nextFunction · 0.85

Calls 3

arrayindexFunction · 0.85
getgenericFunction · 0.85
luaG_runerrorFunction · 0.85

Tested by

no test coverage detected