Skip to content

Commit

Permalink
don't require any Lua functions (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
cldellow authored Oct 13, 2024
1 parent e42aaa7 commit 76ef3e8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions include/osm_lua_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class OsmLuaProcessing {
// Do we have Lua routines for non-MP relations?
bool canReadRelations();
bool canPostScanRelations();
bool canWriteNodes();
bool canWriteWays();
bool canWriteRelations();

// Shapefile tag remapping
Expand Down Expand Up @@ -264,6 +266,8 @@ class OsmLuaProcessing {
bool supportsRemappingShapefiles;
bool supportsReadingRelations;
bool supportsPostScanRelations;
bool supportsWritingNodes;
bool supportsWritingWays;
bool supportsWritingRelations;
const class ShpMemTiles &shpMemTiles;
class OsmMemTiles &osmMemTiles;
Expand Down
15 changes: 14 additions & 1 deletion src/osm_lua_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ OsmLuaProcessing::OsmLuaProcessing(
supportsRemappingShapefiles = !!luaState["attribute_function"];
supportsReadingRelations = !!luaState["relation_scan_function"];
supportsPostScanRelations = !!luaState["relation_postscan_function"];
supportsWritingNodes = !!luaState["node_function"];
supportsWritingWays = !!luaState["way_function"];
supportsWritingRelations = !!luaState["relation_function"];

// ---- Call init_function of Lua logic
Expand Down Expand Up @@ -272,6 +274,14 @@ bool OsmLuaProcessing::canPostScanRelations() {
return supportsPostScanRelations;
}

bool OsmLuaProcessing::canWriteNodes() {
return supportsWritingNodes;
}

bool OsmLuaProcessing::canWriteWays() {
return supportsWritingWays;
}

bool OsmLuaProcessing::canWriteRelations() {
return supportsWritingRelations;
}
Expand Down Expand Up @@ -1064,7 +1074,10 @@ void OsmLuaProcessing::setRelation(
// Start Lua processing for relation
if (!isNativeMP && !supportsWritingRelations) return;
try {
luaState[isNativeMP ? "way_function" : "relation_function"]();
if (isNativeMP && supportsWritingWays)
luaState["way_function"]();
else if (!isNativeMP && supportsWritingRelations)
luaState["relation_function"]();
} catch(luaProcessingException &e) {
std::cerr << "Lua error on relation " << originalOsmID << std::endl;
exit(1);
Expand Down
4 changes: 2 additions & 2 deletions src/pbf_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool PbfProcessor::ReadNodes(OsmLuaProcessing& output, PbfReader::PrimitiveGroup
}

bool emitted = false;
if (!tags.empty() && nodeKeys.filter(tags)) {
if (output.canWriteNodes() && !tags.empty() && nodeKeys.filter(tags)) {
emitted = output.setNode(static_cast<NodeID>(nodeId), latplon, tags);
}

Expand Down Expand Up @@ -142,7 +142,7 @@ bool PbfProcessor::ReadWays(
if (llVec.empty()) continue;

try {
bool emitted = output.setWay(static_cast<WayID>(pbfWay.id), llVec, tags);
bool emitted = output.canWriteWays() && output.setWay(static_cast<WayID>(pbfWay.id), llVec, tags);

// If we need it for later, store the way's coordinates in the global way store
if (emitted || osmStore.way_is_used(wayId)) {
Expand Down

0 comments on commit 76ef3e8

Please sign in to comment.