Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with reading Set values from Lua scripts. #6285

Merged
merged 3 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
- Changes from 5.26.0
- API:
- FIXED: Fix inefficient osrm-routed connection handling [#6113](https://github.com/Project-OSRM/osrm-backend/pull/6113)
- Misc:
- FIXED: Fix bug with reading Set values from Lua scripts. [#6285](https://github.com/Project-OSRM/osrm-backend/pull/6285)
- Build:
- CHANGED: Enable even more clang-tidy checks. [#6273](https://github.com/Project-OSRM/osrm-backend/pull/6273)
- CHANGED: Configure CMake to not build flatbuffers tests and samples. [#6274](https://github.com/Project-OSRM/osrm-backend/pull/6274)
Expand Down
17 changes: 17 additions & 0 deletions features/foot/names.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,20 @@ Feature: Foot - Street names in instructions
When I route I should get
| from | to | route | ref |
| a | c | My Way,, | ,A7,A7 |


Scenario: Foot - Combines named roads with suffix changes
Given the node map
"""
a b c d
"""

And the ways
| nodes | name |
| ab | High Street W |
| bc | High Street E |
| cd | Market Street |

When I route I should get
| from | to | route |
| a | d | High Street W,Market Street,Market Street |
4 changes: 2 additions & 2 deletions features/foot/restrictions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Feature: Foot - Turn restrictions
When I route I should get
| from | to | route |
| s | w | sj,wj,wj |
| s | n | sj,nj,nj |
| s | n | sj,nj |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this test will start failing if we just change Set to Sequence here (without changes from this PR)

suffix_list = Set {

| s | e | sj,ej,ej |

@only_turning
Expand All @@ -55,7 +55,7 @@ Feature: Foot - Turn restrictions
When I route I should get
| from | to | route |
| s | w | sj,wj,wj |
| s | n | sj,nj,nj |
| s | n | sj,nj |
| s | e | sj,ej,ej |

@except
Expand Down
24 changes: 22 additions & 2 deletions src/extractor/scripting_environment_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,26 @@ Sol2ScriptingEnvironment::GetStringListFromFunction(const std::string &function_
return strings;
}

namespace
{

// string list can be defined either as a Set(see profiles/lua/set.lua) or as a Sequence (see
// profiles/lua/sequence.lua) `Set` is a table with keys that are actual values we are looking for
// and values that always `true`. `Sequence` is a table with keys that are indices and values that
// are actual values we are looking for.

std::string GetSetOrSequenceValue(const std::pair<sol::object, sol::object> &pair)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
if (pair.second.is<std::string>())
{
return pair.second.as<std::string>();
}
BOOST_ASSERT(pair.first.is<std::string>());
return pair.first.as<std::string>();
}

} // namespace

std::vector<std::string>
Sol2ScriptingEnvironment::GetStringListFromTable(const std::string &table_name)
{
Expand All @@ -954,7 +974,7 @@ Sol2ScriptingEnvironment::GetStringListFromTable(const std::string &table_name)
{
for (auto &&pair : table)
{
strings.push_back(pair.second.as<std::string>());
strings.emplace_back(GetSetOrSequenceValue(pair));
}
}
return strings;
Expand Down Expand Up @@ -989,7 +1009,7 @@ Sol2ScriptingEnvironment::GetStringListsFromTable(const std::string &table_name)
std::vector<std::string> inner_vector;
for (const auto &inner_pair : inner_table)
{
inner_vector.push_back(inner_pair.first.as<std::string>());
inner_vector.emplace_back(GetSetOrSequenceValue(inner_pair));
}
string_lists.push_back(std::move(inner_vector));
}
Expand Down