- if (lua_pcall(L, nargs + 2, 1, errorhandler)) {
- script_error(L);
+ int result = lua_pcall(L, nargs + 2, 1, error_handler);
+ if (result != 0)
+ script_error(L, result, NULL, fxn);
+
+ lua_remove(L, error_handler);
+}
+
+static void script_log(lua_State *L, const std::string &message,
+ std::ostream &log_to, bool do_error, int stack_depth)
+{
+ lua_Debug ar;
+
+ log_to << message << " ";
+ if (lua_getstack(L, stack_depth, &ar)) {
+ FATAL_ERROR_IF(!lua_getinfo(L, "Sl", &ar), "lua_getinfo() failed");
+ log_to << "(at " << ar.short_src << ":" << ar.currentline << ")";
+ } else {
+ log_to << "(at ?:?)";