MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / findindex

Function findindex

src/Chain/libraries/glua/ltable.cpp:168–192  ·  view source on GitHub ↗

** TODO�� ��key����Ȼ���ٱ��� ** 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

166** beginning of a traversal is signaled by 0.
167*/
168static unsigned int findindex(lua_State *L, Table *t, StkId key) {
169 unsigned int i;
170 if (ttisnil(key)) return 0; /* first iteration */
171 i = arrayindex(key);
172 if (i != 0 && i <= t->sizearray) /* is 'key' inside array part? */
173 return i; /* yes; that's the index */
174 else {
175 int nx;
176 Node *n = mainposition(t, key);
177 for (;;) { /* check whether 'key' is somewhere in the chain */
178 /* key may be dead already, but it is ok to use it in 'next' */
179 if (luaV_rawequalobj(gkey(n), key) ||
180 (ttisdeadkey(gkey(n)) && iscollectable(key) &&
181 deadvalue(gkey(n)) == gcvalue(key))) {
182 i = cast_int(n - gnode(t, 0)); /* key index in hash table */
183 /* hash elements are numbered after array ones */
184 return (i + 1) + t->sizearray;
185 }
186 nx = gnext(n);
187 if (nx == 0)
188 luaG_runerror(L, "invalid key to 'next'"); /* key not found */
189 else n += nx;
190 }
191 }
192}
193
194static std::string lua_value_to_str(const TValue *key)
195{

Callers

nothing calls this directly

Calls 3

arrayindexFunction · 0.85
mainpositionFunction · 0.85
luaG_runerrorFunction · 0.85

Tested by

no test coverage detected