move initialization of Lua error callback into scripting environment

This commit is contained in:
Dennis Luxen 2014-11-19 09:49:39 +01:00
parent f3e3eda69e
commit 288c241fb4
2 changed files with 11 additions and 16 deletions

View File

@ -65,19 +65,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
namespace
{
int lua_error_callback(lua_State *L) // This is so I can use my own function as an
// exception handler, pcall_log()
{
luabind::object error_msg(luabind::from_stack(L, -1));
std::ostringstream error_stream;
error_stream << error_msg;
throw OSRMException("ERROR occured in profile script:\n" + error_stream.str());
}
}
int Extractor::Run(int argc, char *argv[]) int Extractor::Run(int argc, char *argv[])
{ {
ExtractorConfig extractor_config; ExtractorConfig extractor_config;
@ -178,9 +165,6 @@ int Extractor::Run(int argc, char *argv[])
timestamp_out.write(timestamp.c_str(), timestamp.length()); timestamp_out.write(timestamp.c_str(), timestamp.length());
timestamp_out.close(); timestamp_out.close();
// lua_State *lua_state = scripting_environment.getLuaState();
luabind::set_pcall_callback(&lua_error_callback);
// initialize vectors holding parsed objects // initialize vectors holding parsed objects
tbb::concurrent_vector<std::pair<std::size_t, ExtractionNode>> resulting_nodes; tbb::concurrent_vector<std::pair<std::size_t, ExtractionNode>> resulting_nodes;
tbb::concurrent_vector<std::pair<std::size_t, ExtractionWay>> resulting_ways; tbb::concurrent_vector<std::pair<std::size_t, ExtractionWay>> resulting_ways;

View File

@ -48,7 +48,17 @@ 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
// exception handler, pcall_log()
{
luabind::object error_msg(luabind::from_stack(L, -1));
std::ostringstream error_stream;
error_stream << error_msg;
throw OSRMException("ERROR occured in profile script:\n" + error_stream.str());
} }
}
ScriptingEnvironment::ScriptingEnvironment(const char *file_name) ScriptingEnvironment::ScriptingEnvironment(const char *file_name)
: file_name(file_name) : file_name(file_name)
@ -129,6 +139,7 @@ lua_State *ScriptingEnvironment::getLuaState()
ref = state; ref = state;
initLuaState(ref.get()); initLuaState(ref.get());
} }
luabind::set_pcall_callback(&lua_error_callback);
return ref.get(); return ref.get();
} }