Added nil check to table conversion

This commit is contained in:
Desone Burns II 2020-11-23 13:21:55 -07:00
parent e693b8963a
commit f6065de494

View File

@ -259,7 +259,7 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
"version", "version",
&osmium::Way::version, &osmium::Way::version,
"get_nodes", "get_nodes",
[](const osmium::Way &way) { return sol::as_table(&way.nodes()); }, [&context](const osmium::Way &way) { return sol::as_table(&way.nodes()); },
"get_location_tag", "get_location_tag",
[&context, &get_location_tag](const osmium::Way &way, const char *key) { [&context, &get_location_tag](const osmium::Way &way, const char *key) {
// HEURISTIC: use a single node (last) of the way to localize the way // HEURISTIC: use a single node (last) of the way to localize the way
@ -944,6 +944,9 @@ Sol2ScriptingEnvironment::GetStringListFromTable(const std::string &table_name)
auto &context = GetSol2Context(); auto &context = GetSol2Context();
BOOST_ASSERT(context.state.lua_state() != nullptr); BOOST_ASSERT(context.state.lua_state() != nullptr);
std::vector<std::string> strings; std::vector<std::string> strings;
if(context.profile_table[table_name] == sol::nil){
return strings;
}
sol::table table = context.profile_table[table_name]; sol::table table = context.profile_table[table_name];
if (table.valid()) if (table.valid())
{ {
@ -962,6 +965,9 @@ Sol2ScriptingEnvironment::GetStringListsFromTable(const std::string &table_name)
auto &context = GetSol2Context(); auto &context = GetSol2Context();
BOOST_ASSERT(context.state.lua_state() != nullptr); BOOST_ASSERT(context.state.lua_state() != nullptr);
if(context.profile_table[table_name] == sol::nil){
return string_lists;
}
sol::table table = context.profile_table[table_name]; sol::table table = context.profile_table[table_name];
if (!table.valid()) if (!table.valid())
{ {