diff --git a/include/osm_lua_processing.h b/include/osm_lua_processing.h index d21b83b0..092881c1 100644 --- a/include/osm_lua_processing.h +++ b/include/osm_lua_processing.h @@ -244,6 +244,7 @@ class OsmLuaProcessing { struct luaProcessingException :std::exception {}; const TagMap* currentTags; + bool isPostScanRelation; // processing a relation in postScanRelation private: /// Internal: clear current cached state @@ -290,7 +291,6 @@ class OsmLuaProcessing { bool relationAccepted; // in scanRelation, whether we're using a non-MP relation std::vector> relationList; // in processNode/processWay, list of relations this entity is in, and its role int relationSubscript = -1; // in processWay, position in the relation list - bool isPostScanRelation; // processing a relation in postScanRelation int32_t lon,latp; ///< Node coordinates LatpLonVec const *llVecPtr; diff --git a/src/osm_lua_processing.cpp b/src/osm_lua_processing.cpp index cf95bc79..63ff807f 100644 --- a/src/osm_lua_processing.cpp +++ b/src/osm_lua_processing.cpp @@ -16,7 +16,6 @@ using namespace std; const std::string EMPTY_STRING = ""; thread_local kaguya::State *g_luaState = nullptr; thread_local OsmLuaProcessing* osmLuaProcessing = nullptr; -thread_local bool inPostScanRelations = false; void handleOsmLuaProcessingUserSignal(int signum) { osmLuaProcessing->handleUserSignal(signum); @@ -68,7 +67,10 @@ template<> struct kaguya::lua_type_traits { size_t size = 0; const char* buffer = lua_tolstring(l, index, &size); - if (inPostScanRelations) { + if (osmLuaProcessing->isPostScanRelation) { + // In this phase, the Holds/Find functions directly query a + // traditional string->string map, so just ensure we expose + // the string. rv.stringValue = std::string(buffer, size); return rv; } @@ -134,11 +136,19 @@ template<> struct kaguya::lua_type_traits { }; std::string rawId() { return osmLuaProcessing->Id(); } -bool rawHolds(const KnownTagKey& key) { return key.found; } -bool rawHoldsPostScanRelations(const KnownTagKey& key) { return key.found; } +bool rawHolds(const KnownTagKey& key) { + if (osmLuaProcessing->isPostScanRelation) { + return osmLuaProcessing->Holds(key.stringValue); + } + + return key.found; +} bool rawHasTags() { return osmLuaProcessing->HasTags(); } void rawSetTag(const std::string &key, const std::string &value) { return osmLuaProcessing->SetTag(key, value); } const std::string rawFind(const KnownTagKey& key) { + if (osmLuaProcessing->isPostScanRelation) + return osmLuaProcessing->Find(key.stringValue); + if (key.found) { auto value = *(osmLuaProcessing->currentTags->getValueFromKey(key.index)); return std::string(value.data(), value.size()); @@ -146,9 +156,6 @@ const std::string rawFind(const KnownTagKey& key) { return EMPTY_STRING; } -const std::string rawFindPostScanRelations(const KnownTagKey& key) { - return osmLuaProcessing->Find(key.stringValue); -} std::vector rawFindIntersecting(const std::string &layerName) { return osmLuaProcessing->FindIntersecting(layerName); } bool rawIntersects(const std::string& layerName) { return osmLuaProcessing->Intersects(layerName); } std::vector rawFindCovering(const std::string& layerName) { return osmLuaProcessing->FindCovering(layerName); } @@ -951,11 +958,6 @@ bool OsmLuaProcessing::scanRelation(WayID id, const TagMap& tags) { void OsmLuaProcessing::postScanRelations() { if (!supportsPostScanRelations) return; - // Adjust the function pointers for tag-related functions - inPostScanRelations = true; - luaState["Holds"] = &rawHoldsPostScanRelations; - luaState["Find"] = &rawFindPostScanRelations; - for (const auto &relp : osmStore.scannedRelations.relationsForRelations) { reset(); isPostScanRelation = true;