MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / findindex

Function findindex

3rd/lua-5.4.3/src/ltable.c:320–335  ·  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

318** beginning of a traversal is signaled by 0.
319*/
320static 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
338int 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