Skip to content

Commit

Permalink
Explicitly copy way.nodes() into vector to have correct meta functions
Browse files Browse the repository at this point in the history
  • Loading branch information
oxidase committed Jan 3, 2017
1 parent f48bbb7 commit 1b37df9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
28 changes: 28 additions & 0 deletions features/options/extract/lua.feature
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 1 addition & 3 deletions src/extractor/scripting_environment_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ template <class T> double lonToDouble(T const &object)
return static_cast<double>(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)
Expand Down Expand Up @@ -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<osmium::WayNodeList>("WayNodeList");

// Keep in mind .location is undefined since we're not using libosmium's location cache
context.state.new_usertype<osmium::NodeRef>("NodeRef", "id", &osmium::NodeRef::ref);

Expand Down

0 comments on commit 1b37df9

Please sign in to comment.