/* search for 'objidx' in table at index -1. return 1 + string at top if find a good name.  */
static int findfield(lua_State *L, int objidx, int level)
/* search for 'objidx' in table at index -1. return 1 + string at top if find a good name.  */
static int findfield(lua_State *L, int objidx, int level)
{
    if (lua_type(L, -2) == LUA_TSTRING) {
      if (lua_rawequal(L, objidx, -1)) {
        lua_pop(L, 1);
        return 1;
      }
      else if (findfield(L, objidx, level - 1)) {
        lua_remove(L, -2);
        lua_pushliteral(L, ".");
        lua_insert(L, -2);
        lua_concat(L, 3);
        return 1;
      }
    }
    lua_pop(L, 1);
  }
  return 0;
}