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;
explicit ScriptingEnvironment(const std::string &file_name);
lua_State *get_lua_state();
lua_State *GetLuaState();
private:
void init_lua_state(lua_State *lua_state);
void InitLuaState(lua_State *lua_state);
std::mutex init_mutex;
std::string file_name;
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..";
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"))
{
@ -135,7 +135,7 @@ int extractor::run()
tbb::concurrent_vector<boost::optional<InputRestrictionContainer>> resulting_restrictions;
// 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())
{
@ -158,7 +158,7 @@ int extractor::run()
{
ExtractionNode result_node;
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)
{

View File

@ -19,9 +19,8 @@
#include <algorithm>
#include <iterator>
namespace
{
int lua_error_callback(lua_State *lua_state)
namespace {
int luaErrorCallback(lua_State *lua_state)
{
std::string error_msg = lua_tostring(lua_state, -1);
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"))
{
luabind::set_pcall_callback(&lua_error_callback);
luabind::set_pcall_callback(&luaErrorCallback);
// get list of turn restriction exceptions
luabind::call_function<void>(lua_state, "get_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, "");
}
int lua_error_callback(lua_State *L) // This is so I can use my own function as an
// exception handler, pcall_log()
// Error handler
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;
error_stream << error_msg;
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;
}
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;
@ -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);
bool initialized = false;
@ -135,9 +135,9 @@ lua_State *ScriptingEnvironment::get_lua_state()
{
std::shared_ptr<lua_State> state(luaL_newstate(), lua_close);
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();
}