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

Function findindex

third-party/lua-5.2.4/src/ltable.c:144–166  ·  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 -1. */

Source from the content-addressed store, hash-verified

142** beginning of a traversal is signaled by -1.
143*/
144static int findindex (lua_State *L, Table *t, StkId key) {
145 int i;
146 if (ttisnil(key)) return -1; /* first iteration */
147 i = arrayindex(key);
148 if (0 < i && i <= t->sizearray) /* is `key' inside array part? */
149 return i-1; /* yes; that's the index (corrected to C) */
150 else {
151 Node *n = mainposition(t, key);
152 for (;;) { /* check whether `key' is somewhere in the chain */
153 /* key may be dead already, but it is ok to use it in `next' */
154 if (luaV_rawequalobj(gkey(n), key) ||
155 (ttisdeadkey(gkey(n)) && iscollectable(key) &&
156 deadvalue(gkey(n)) == gcvalue(key))) {
157 i = cast_int(n - gnode(t, 0)); /* key index in hash table */
158 /* hash elements are numbered after array ones */
159 return i + t->sizearray;
160 }
161 else n = gnext(n);
162 if (n == NULL)
163 luaG_runerror(L, "invalid key to " LUA_QL("next")); /* key not found */
164 }
165 }
166}
167
168
169int luaH_next (lua_State *L, Table *t, StkId key) {

Callers 1

luaH_nextFunction · 0.70

Calls 3

arrayindexFunction · 0.70
mainpositionFunction · 0.70
luaG_runerrorFunction · 0.70

Tested by

no test coverage detected