MCPcopy Create free account
hub / github.com/F-Stack/f-stack / findfield

Function findfield

freebsd/contrib/openzfs/module/lua/lauxlib.c:37–58  ·  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

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

Callers 1

pushglobalfuncnameFunction · 0.85

Calls 7

lua_pushnilFunction · 0.70
lua_nextFunction · 0.70
lua_typeFunction · 0.70
lua_rawequalFunction · 0.70
lua_removeFunction · 0.70
lua_insertFunction · 0.70
lua_concatFunction · 0.70

Tested by

no test coverage detected