MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / findindex

Function findindex

third-party/lua-5.1.5/src/ltable.c:137–159  ·  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 signalled by -1. */

Source from the content-addressed store, hash-verified

135** beginning of a traversal is signalled by -1.
136*/
137static int findindex (lua_State *L, Table *t, StkId key) {
138 int i;
139 if (ttisnil(key)) return -1; /* first iteration */
140 i = arrayindex(key);
141 if (0 < i && i <= t->sizearray) /* is `key' inside array part? */
142 return i-1; /* yes; that's the index (corrected to C) */
143 else {
144 Node *n = mainposition(t, key);
145 do { /* check whether `key' is somewhere in the chain */
146 /* key may be dead already, but it is ok to use it in `next' */
147 if (luaO_rawequalObj(key2tval(n), key) ||
148 (ttype(gkey(n)) == LUA_TDEADKEY && iscollectable(key) &&
149 gcvalue(gkey(n)) == gcvalue(key))) {
150 i = cast_int(n - gnode(t, 0)); /* key index in hash table */
151 /* hash elements are numbered after array ones */
152 return i + t->sizearray;
153 }
154 else n = gnext(n);
155 } while (n);
156 luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */
157 return 0; /* to avoid warnings */
158 }
159}
160
161
162int luaH_next (lua_State *L, Table *t, StkId key) {

Callers 1

luaH_nextFunction · 0.70

Calls 4

luaO_rawequalObjFunction · 0.85
arrayindexFunction · 0.70
mainpositionFunction · 0.70
luaG_runerrorFunction · 0.70

Tested by

no test coverage detected