MCPcopy Create free account
hub / github.com/DFHack/dfhack / findfield

Function findfield

depends/lua/src/lauxlib.c:46–67  ·  view source on GitHub ↗

** search for 'objidx' in table at index -1. ** return 1 + string at top if find a good name. */

Source from the content-addressed store, hash-verified

44** return 1 + string at top if find a good name.
45*/
46static int findfield (lua_State *L, int objidx, int level) {
47 if (level == 0 || !lua_istable(L, -1))
48 return 0; /* not found */
49 lua_pushnil(L); /* start 'next' loop */
50 while (lua_next(L, -2)) { /* for each pair in table */
51 if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */
52 if (lua_rawequal(L, objidx, -1)) { /* found object? */
53 lua_pop(L, 1); /* remove value (but keep name) */
54 return 1;
55 }
56 else if (findfield(L, objidx, level - 1)) { /* try recursively */
57 lua_remove(L, -2); /* remove table (but keep name) */
58 lua_pushliteral(L, ".");
59 lua_insert(L, -2); /* place '.' between the two names */
60 lua_concat(L, 3);
61 return 1;
62 }
63 }
64 lua_pop(L, 1); /* remove value */
65 }
66 return 0; /* not found */
67}
68
69
70/*

Callers 1

pushglobalfuncnameFunction · 0.85

Calls 5

lua_pushnilFunction · 0.85
lua_nextFunction · 0.85
lua_typeFunction · 0.85
lua_rawequalFunction · 0.85
lua_concatFunction · 0.85

Tested by

no test coverage detected