unsigned tagtransform::lua_filter_rel_member_tags(const taglist_t &rel_tags, const multitaglist_t &member_tags, const rolelist_t &member_roles, int *member_superseeded, int *make_boundary, int *make_polygon, int *roads, taglist_t &out_tags) { lua_getglobal(L, m_rel_mem_func.c_str()); lua_newtable(L); /* relations key value table */ for (taglist_t::const_iterator it = rel_tags.begin(); it != rel_tags.end(); ++it) { lua_pushstring(L, it->key.c_str()); lua_pushstring(L, it->value.c_str()); lua_rawset(L, -3); } lua_newtable(L); /* member tags table */ int idx = 1; for (multitaglist_t::const_iterator list = member_tags.begin(); list != member_tags.end(); ++list) { lua_pushnumber(L, idx++); lua_newtable(L); /* member key value table */ for (taglist_t::const_iterator it = list->begin(); it != list->end(); ++it) { lua_pushstring(L, it->key.c_str()); lua_pushstring(L, it->value.c_str()); lua_rawset(L, -3); } lua_rawset(L, -3); } lua_newtable(L); /* member roles table */ for (size_t i = 0; i < member_roles.size(); i++) { lua_pushnumber(L, i + 1); lua_pushstring(L, member_roles[i]->c_str()); lua_rawset(L, -3); } lua_pushnumber(L, member_roles.size()); if (lua_pcall(L,4,6,0)) { fprintf(stderr, "Failed to execute lua function for relation tag processing: %s\n", lua_tostring(L, -1)); /* lua function failed */ return 1; } *roads = lua_tointeger(L, -1); lua_pop(L,1); *make_polygon = lua_tointeger(L, -1); lua_pop(L,1); *make_boundary = lua_tointeger(L,-1); lua_pop(L,1); lua_pushnil(L); for (size_t i = 0; i < member_tags.size(); i++) { if (lua_next(L,-2)) { member_superseeded[i] = lua_tointeger(L,-1); lua_pop(L,1); } else { fprintf(stderr, "Failed to read member_superseeded from lua function\n"); } } lua_pop(L,2); lua_pushnil(L); while (lua_next(L,-2) != 0) { const char *key = lua_tostring(L,-2); const char *value = lua_tostring(L,-1); out_tags.push_back(tag(key, value)); lua_pop(L,1); } lua_pop(L,1); int filter = lua_tointeger(L, -1); lua_pop(L,1); return filter; }
unsigned lua_tagtransform_t::filter_rel_member_tags( taglist_t const &rel_tags, multitaglist_t const &members_tags, rolelist_t const &member_roles, int *member_superseded, int *make_boundary, int *make_polygon, int *roads, export_list const &, taglist_t &out_tags, bool) { lua_getglobal(L, m_rel_mem_func.c_str()); lua_newtable(L); /* relations key value table */ for (const auto &rel_tag : rel_tags) { lua_pushstring(L, rel_tag.key.c_str()); lua_pushstring(L, rel_tag.value.c_str()); lua_rawset(L, -3); } lua_newtable(L); /* member tags table */ int idx = 1; for (const auto &member_tags : members_tags) { lua_pushnumber(L, idx++); lua_newtable(L); /* member key value table */ for (const auto &member_tag : member_tags) { lua_pushstring(L, member_tag.key.c_str()); lua_pushstring(L, member_tag.value.c_str()); lua_rawset(L, -3); } lua_rawset(L, -3); } lua_newtable(L); /* member roles table */ for (size_t i = 0; i < member_roles.size(); i++) { lua_pushnumber(L, i + 1); lua_pushstring(L, member_roles[i]); lua_rawset(L, -3); } lua_pushnumber(L, member_roles.size()); if (lua_pcall(L, 4, 6, 0)) { fprintf( stderr, "Failed to execute lua function for relation tag processing: %s\n", lua_tostring(L, -1)); /* lua function failed */ return 1; } *roads = (int)lua_tointeger(L, -1); lua_pop(L, 1); *make_polygon = (int)lua_tointeger(L, -1); lua_pop(L, 1); *make_boundary = (int)lua_tointeger(L, -1); lua_pop(L, 1); lua_pushnil(L); for (size_t i = 0; i < members_tags.size(); i++) { if (lua_next(L, -2)) { member_superseded[i] = (int)lua_tointeger(L, -1); lua_pop(L, 1); } else { fprintf(stderr, "Failed to read member_superseded from lua function\n"); } } lua_pop(L, 2); lua_pushnil(L); while (lua_next(L, -2) != 0) { const char *key = lua_tostring(L, -2); const char *value = lua_tostring(L, -1); out_tags.push_back(tag_t(key, value)); lua_pop(L, 1); } lua_pop(L, 1); unsigned filter = (unsigned)lua_tointeger(L, -1); lua_pop(L, 1); return filter; }