Fix naming in ScriptingEnvironment

This commit is contained in:
Patrick Niklaus 2016-01-04 11:44:23 +01:00
parent b209952ce0
commit ccd3872bf1
4 changed files with 15 additions and 16 deletions

View File

@ -21,10 +21,10 @@ class ScriptingEnvironment
ScriptingEnvironment() = delete; ScriptingEnvironment() = delete;
explicit ScriptingEnvironment(const std::string &file_name); explicit ScriptingEnvironment(const std::string &file_name);
lua_State *get_lua_state(); lua_State *GetLuaState();
private: private:
void init_lua_state(lua_State *lua_state); void InitLuaState(lua_State *lua_state);
std::mutex init_mutex; std::mutex init_mutex;
std::string file_name; std::string file_name;
tbb::enumerable_thread_specific<std::shared_ptr<lua_State>> script_contexts; tbb::enumerable_thread_specific<std::shared_ptr<lua_State>> script_contexts;

View File

@ -99,7 +99,7 @@ int extractor::run()
SimpleLogger().Write() << "Parsing in progress.."; SimpleLogger().Write() << "Parsing in progress..";
TIMER_START(parsing); TIMER_START(parsing);
lua_State *segment_state = scripting_environment.get_lua_state(); lua_State *segment_state = scripting_environment.GetLuaState();
if (lua_function_exists(segment_state, "source_function")) if (lua_function_exists(segment_state, "source_function"))
{ {
@ -135,7 +135,7 @@ int extractor::run()
tbb::concurrent_vector<boost::optional<InputRestrictionContainer>> resulting_restrictions; tbb::concurrent_vector<boost::optional<InputRestrictionContainer>> resulting_restrictions;
// setup restriction parser // setup restriction parser
const RestrictionParser restriction_parser(scripting_environment.get_lua_state()); const RestrictionParser restriction_parser(scripting_environment.GetLuaState());
while (const osmium::memory::Buffer buffer = reader.read()) while (const osmium::memory::Buffer buffer = reader.read())
{ {
@ -158,7 +158,7 @@ int extractor::run()
{ {
ExtractionNode result_node; ExtractionNode result_node;
ExtractionWay result_way; ExtractionWay result_way;
lua_State *local_state = scripting_environment.get_lua_state(); lua_State *local_state = scripting_environment.GetLuaState();
for (auto x = range.begin(), end = range.end(); x != end; ++x) for (auto x = range.begin(), end = range.end(); x != end; ++x)
{ {

View File

@ -19,9 +19,8 @@
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
namespace namespace {
{ int luaErrorCallback(lua_State *lua_state)
int lua_error_callback(lua_State *lua_state)
{ {
std::string error_msg = lua_tostring(lua_state, -1); std::string error_msg = lua_tostring(lua_state, -1);
throw osrm::exception("ERROR occurred in profile script:\n" + error_msg); throw osrm::exception("ERROR occurred in profile script:\n" + error_msg);
@ -60,7 +59,7 @@ void RestrictionParser::ReadRestrictionExceptions(lua_State *lua_state)
{ {
if (lua_function_exists(lua_state, "get_exceptions")) if (lua_function_exists(lua_state, "get_exceptions"))
{ {
luabind::set_pcall_callback(&lua_error_callback); luabind::set_pcall_callback(&luaErrorCallback);
// get list of turn restriction exceptions // get list of turn restriction exceptions
luabind::call_function<void>(lua_state, "get_exceptions", luabind::call_function<void>(lua_state, "get_exceptions",
boost::ref(restriction_exceptions)); boost::ref(restriction_exceptions));

View File

@ -26,10 +26,10 @@ auto get_value_by_key(T const &object, const char *key) -> decltype(object.get_v
return object.get_value_by_key(key, ""); return object.get_value_by_key(key, "");
} }
int lua_error_callback(lua_State *L) // This is so I can use my own function as an // Error handler
// exception handler, pcall_log() int luaErrorCallback(lua_State *state)
{ {
std::string error_msg = lua_tostring(L, -1); std::string error_msg = lua_tostring(state, -1);
std::ostringstream error_stream; std::ostringstream error_stream;
error_stream << error_msg; error_stream << error_msg;
throw osrm::exception("ERROR occurred in profile script:\n" + error_stream.str()); throw osrm::exception("ERROR occurred in profile script:\n" + error_stream.str());
@ -41,7 +41,7 @@ ScriptingEnvironment::ScriptingEnvironment(const std::string &file_name) : file_
SimpleLogger().Write() << "Using script " << file_name; SimpleLogger().Write() << "Using script " << file_name;
} }
void ScriptingEnvironment::init_lua_state(lua_State *lua_state) void ScriptingEnvironment::InitLuaState(lua_State *lua_state)
{ {
typedef double (osmium::Location::*location_member_ptr_type)() const; typedef double (osmium::Location::*location_member_ptr_type)() const;
@ -126,7 +126,7 @@ void ScriptingEnvironment::init_lua_state(lua_State *lua_state)
} }
} }
lua_State *ScriptingEnvironment::get_lua_state() lua_State *ScriptingEnvironment::GetLuaState()
{ {
std::lock_guard<std::mutex> lock(init_mutex); std::lock_guard<std::mutex> lock(init_mutex);
bool initialized = false; bool initialized = false;
@ -135,9 +135,9 @@ lua_State *ScriptingEnvironment::get_lua_state()
{ {
std::shared_ptr<lua_State> state(luaL_newstate(), lua_close); std::shared_ptr<lua_State> state(luaL_newstate(), lua_close);
ref = state; ref = state;
init_lua_state(ref.get()); InitLuaState(ref.get());
} }
luabind::set_pcall_callback(&lua_error_callback); luabind::set_pcall_callback(&luaErrorCallback);
return ref.get(); return ref.get();
} }