MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / findindex

Function findindex

lib/lua/src/ltable.c:331–346  ·  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

329** beginning of a traversal is signaled by 0.
330*/
331static 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
349int 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