Wrap way.nodes() returned reference into sol::as_table
This commit is contained in:
parent
e6ff17ab2a
commit
2640a319c1
28
features/options/extract/lua.feature
Normal file
28
features/options/extract/lua.feature
Normal file
@ -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"
|
@ -74,8 +74,6 @@ template <class T> double lonToDouble(T const &object)
|
|||||||
return static_cast<double>(util::toFloating(object.lon));
|
return static_cast<double>(util::toFloating(object.lon));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto get_nodes_for_way(const osmium::Way &way) -> decltype(way.nodes()) { return way.nodes(); }
|
|
||||||
|
|
||||||
Sol2ScriptingEnvironment::Sol2ScriptingEnvironment(const std::string &file_name)
|
Sol2ScriptingEnvironment::Sol2ScriptingEnvironment(const std::string &file_name)
|
||||||
: file_name(file_name)
|
: file_name(file_name)
|
||||||
{
|
{
|
||||||
@ -184,13 +182,14 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
|
|||||||
"valid",
|
"valid",
|
||||||
&osmium::Location::valid);
|
&osmium::Location::valid);
|
||||||
|
|
||||||
context.state.new_usertype<osmium::Way>("Way",
|
context.state.new_usertype<osmium::Way>(
|
||||||
"get_value_by_key",
|
"Way",
|
||||||
&get_value_by_key<osmium::Way>,
|
"get_value_by_key",
|
||||||
"id",
|
&get_value_by_key<osmium::Way>,
|
||||||
&osmium::Way::id,
|
"id",
|
||||||
"get_nodes",
|
&osmium::Way::id,
|
||||||
&get_nodes_for_way);
|
"get_nodes",
|
||||||
|
[](const osmium::Way &way) { return sol::as_table(way.nodes()); });
|
||||||
|
|
||||||
context.state.new_usertype<osmium::Node>("Node",
|
context.state.new_usertype<osmium::Node>("Node",
|
||||||
"location",
|
"location",
|
||||||
@ -257,8 +256,6 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
|
|||||||
"backward_mode",
|
"backward_mode",
|
||||||
sol::property(&ExtractionWay::get_backward_mode, &ExtractionWay::set_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
|
// 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);
|
context.state.new_usertype<osmium::NodeRef>("NodeRef", "id", &osmium::NodeRef::ref);
|
||||||
|
|
||||||
@ -308,12 +305,12 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
|
|||||||
context.has_segment_function = segment_function.valid();
|
context.has_segment_function = segment_function.valid();
|
||||||
auto maybe_version = context.state.get<sol::optional<int>>("api_version");
|
auto maybe_version = context.state.get<sol::optional<int>>("api_version");
|
||||||
if (maybe_version)
|
if (maybe_version)
|
||||||
{
|
{
|
||||||
context.api_version = *maybe_version;
|
context.api_version = *maybe_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.api_version < SUPPORTED_MIN_API_VERSION ||
|
if (context.api_version < SUPPORTED_MIN_API_VERSION ||
|
||||||
context.api_version > SUPPORTED_MAX_API_VERSION )
|
context.api_version > SUPPORTED_MAX_API_VERSION)
|
||||||
{
|
{
|
||||||
throw util::exception("Invalid profile API version " + std::to_string(context.api_version) +
|
throw util::exception("Invalid profile API version " + std::to_string(context.api_version) +
|
||||||
" only versions from " + std::to_string(SUPPORTED_MIN_API_VERSION) +
|
" only versions from " + std::to_string(SUPPORTED_MIN_API_VERSION) +
|
||||||
|
Loading…
Reference in New Issue
Block a user