From 1b37df90ab3aeefcd200a6c482f0ac1fe0a0ea8a Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Sat, 17 Dec 2016 15:38:14 +0100 Subject: [PATCH] Explicitly copy way.nodes() into vector to have correct meta functions --- features/options/extract/lua.feature | 28 +++++++++++++++++++++ src/extractor/scripting_environment_lua.cpp | 4 +-- 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 features/options/extract/lua.feature diff --git a/features/options/extract/lua.feature b/features/options/extract/lua.feature new file mode 100644 index 00000000000..b1c74b07fc6 --- /dev/null +++ b/features/options/extract/lua.feature @@ -0,0 +1,28 @@ +@extract +Feature: osrm-extract lua ways:get_nodes() + + Background: + Given the node map + """ + a b + """ + And the ways + | nodes | + | ab | + And the data has been saved to disk + + Scenario: osrm-extract - Passing base file + Given the profile file "testbot" extended with + """ + function way_function(way, result) + for _, node in ipairs(way:get_nodes()) do + print('node id ' .. node:id()) + end + result.forward_mode = mode.driving + result.forward_speed = 1 + end + """ + When I run "osrm-extract --profile {profile_file} {osm_file}" + Then it should exit successfully + And stdout should contain "node id 1" + And stdout should contain "node id 2" diff --git a/src/extractor/scripting_environment_lua.cpp b/src/extractor/scripting_environment_lua.cpp index cd5ce0c9512..fe5beaa92f4 100644 --- a/src/extractor/scripting_environment_lua.cpp +++ b/src/extractor/scripting_environment_lua.cpp @@ -74,7 +74,7 @@ template double lonToDouble(T const &object) return static_cast(util::toFloating(object.lon)); } -auto get_nodes_for_way(const osmium::Way &way) -> decltype(way.nodes()) { return way.nodes(); } +auto get_nodes_for_way(const osmium::Way &way) -> decltype(way.nodes()) { return sol::as_table(way.nodes()); } Sol2ScriptingEnvironment::Sol2ScriptingEnvironment(const std::string &file_name) : file_name(file_name) @@ -257,8 +257,6 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context) "backward_mode", sol::property(&ExtractionWay::get_backward_mode, &ExtractionWay::set_backward_mode)); - context.state.new_usertype("WayNodeList"); - // Keep in mind .location is undefined since we're not using libosmium's location cache context.state.new_usertype("NodeRef", "id", &osmium::NodeRef::ref);