** search for 'objidx' in table at index -1. ** return 1 + string at top if find a good name. */
| 44 | ** return 1 + string at top if find a good name. |
| 45 | */ |
| 46 | static 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 | /* |
no test coverage detected