Switch profiles from Lua to library interface

There's now an abstracted interface and no direct calls to Lua anymore.

fixes #1974
This commit is contained in:
Konstantin Käfer
2016-07-11 17:44:58 +02:00
committed by Patrick Niklaus
parent 9b737230d6
commit 1309dd2a0f
15 changed files with 382 additions and 245 deletions
+16 -33
View File
@@ -1,9 +1,9 @@
#include "extractor/restriction_parser.hpp"
#include "extractor/profile_properties.hpp"
#include "extractor/scripting_environment.hpp"
#include "extractor/external_memory_node.hpp"
#include "util/exception.hpp"
#include "util/lua_util.hpp"
#include "util/simple_logger.hpp"
#include <boost/algorithm/string.hpp>
@@ -24,43 +24,26 @@ namespace osrm
namespace extractor
{
namespace
{
int luaErrorCallback(lua_State *lua_state)
{
std::string error_msg = lua_tostring(lua_state, -1);
throw util::exception("ERROR occurred in profile script:\n" + error_msg);
}
}
RestrictionParser::RestrictionParser(lua_State *lua_state, const ProfileProperties &properties)
: use_turn_restrictions(properties.use_turn_restrictions)
RestrictionParser::RestrictionParser(ScriptingEnvironment &scripting_environment)
: use_turn_restrictions(scripting_environment.GetProfileProperties().use_turn_restrictions)
{
if (use_turn_restrictions)
{
ReadRestrictionExceptions(lua_state);
}
}
void RestrictionParser::ReadRestrictionExceptions(lua_State *lua_state)
{
if (util::luaFunctionExists(lua_state, "get_exceptions"))
{
luabind::set_pcall_callback(&luaErrorCallback);
// get list of turn restriction exceptions
luabind::call_function<void>(
lua_state, "get_exceptions", boost::ref(restriction_exceptions));
restriction_exceptions = scripting_environment.GetExceptions();
const unsigned exception_count = restriction_exceptions.size();
util::SimpleLogger().Write() << "Found " << exception_count
<< " exceptions to turn restrictions:";
for (const std::string &str : restriction_exceptions)
if (exception_count)
{
util::SimpleLogger().Write() << " " << str;
util::SimpleLogger().Write() << "Found " << exception_count
<< " exceptions to turn restrictions:";
for (const std::string &str : restriction_exceptions)
{
util::SimpleLogger().Write() << " " << str;
}
}
else
{
util::SimpleLogger().Write() << "Found no exceptions to turn restrictions";
}
}
else
{
util::SimpleLogger().Write() << "Found no exceptions to turn restrictions";
}
}