Address PR comments

Renamed lua_function_exists and removes unused print function
This commit is contained in:
Patrick Niklaus
2016-03-22 21:23:25 +01:00
parent a781c36876
commit 38db495879
13 changed files with 30 additions and 30 deletions
+2 -2
View File
@@ -278,7 +278,7 @@ void EdgeBasedGraphFactory::GenerateEdgeExpandedEdges(
util::SimpleLogger().Write() << "generating edge-expanded edges";
BOOST_ASSERT(lua_state != nullptr);
const bool use_turn_function = util::lua_function_exists(lua_state, "turn_function");
const bool use_turn_function = util::luaFunctionExists(lua_state, "turn_function");
std::size_t node_based_edge_counter = 0;
std::size_t original_edges_counter = 0;
@@ -454,7 +454,7 @@ int EdgeBasedGraphFactory::GetTurnPenalty(double angle, lua_State *lua_state) co
{
// call lua profile to compute turn penalty
double penalty = luabind::call_function<double>(lua_state, "turn_function", 180. - angle);
return static_cast<int>(penalty);
return boost::numeric_cast<int>(penalty);
}
catch (const luabind::error &er)
{
+1 -1
View File
@@ -288,7 +288,7 @@ void ExtractionContainers::PrepareEdges(lua_State *segment_state)
const auto all_edges_list_end_ = all_edges_list.end();
const auto all_nodes_list_end_ = all_nodes_list.end();
auto has_segment_function = util::lua_function_exists(segment_state, "segment_function");
const auto has_segment_function = util::luaFunctionExists(segment_state, "segment_function");
while (edge_iterator != all_edges_list_end_ && node_iterator != all_nodes_list_end_)
{
+1 -1
View File
@@ -111,7 +111,7 @@ int Extractor::run()
auto& main_context = scripting_environment.GetContex();
// setup raster sources
if (util::lua_function_exists(main_context.state, "source_function"))
if (util::luaFunctionExists(main_context.state, "source_function"))
{
luabind::call_function<void>(main_context.state, "source_function");
}
-4
View File
@@ -13,10 +13,6 @@ namespace osrm
namespace extractor
{
GraphCompressor::GraphCompressor()
{
}
void GraphCompressor::Compress(const std::unordered_set<NodeID> &barrier_nodes,
const std::unordered_set<NodeID> &traffic_lights,
RestrictionMap &restriction_map,
+1 -1
View File
@@ -44,7 +44,7 @@ RestrictionParser::RestrictionParser(lua_State *lua_state, const ProfileProperti
void RestrictionParser::ReadRestrictionExceptions(lua_State *lua_state)
{
if (util::lua_function_exists(lua_state, "get_exceptions"))
if (util::luaFunctionExists(lua_state, "get_exceptions"))
{
luabind::set_pcall_callback(&luaErrorCallback);
// get list of turn restriction exceptions
+3 -8
View File
@@ -8,6 +8,7 @@
#include "extractor/raster_source.hpp"
#include "extractor/profile_properties.hpp"
#include "util/lua_util.hpp"
#include "util/make_unique.hpp"
#include "util/exception.hpp"
#include "util/simple_logger.hpp"
#include "util/typedefs.hpp"
@@ -52,10 +53,6 @@ int luaErrorCallback(lua_State *state)
}
}
ScriptingEnvironment::Context::Context() : state(luaL_newstate()) {}
ScriptingEnvironment::Context::~Context() { lua_close(state); }
ScriptingEnvironment::ScriptingEnvironment(const std::string &file_name) : file_name(file_name)
{
util::SimpleLogger().Write() << "Using script " << file_name;
@@ -73,8 +70,7 @@ void ScriptingEnvironment::InitContext(ScriptingEnvironment::Context &context)
// Add our function to the state's global scope
luabind::module(context.state)
[luabind::def("print", util::LUA_print<std::string>),
luabind::def("durationIsValid", durationIsValid),
[luabind::def("durationIsValid", durationIsValid),
luabind::def("parseDuration", parseDuration),
luabind::class_<TravelMode>("mode")
.enum_("enums")[luabind::value("inaccessible", TRAVEL_MODE_INACCESSIBLE),
@@ -176,8 +172,7 @@ ScriptingEnvironment::Context &ScriptingEnvironment::GetContex()
auto &ref = script_contexts.local(initialized);
if (!initialized)
{
std::shared_ptr<Context> state = std::make_shared<Context>();
ref = state;
ref = util::make_unique<Context>();
InitContext(*ref);
}
luabind::set_pcall_callback(&luaErrorCallback);