aboutsummaryrefslogtreecommitdiff
path: root/src/script/common
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-08-11 22:27:54 -0400
committerkwolekr <kwolekr@minetest.net>2015-08-12 23:56:12 -0400
commit2b04ab874d75711bc021a0cd8dc7fca68f4e6929 (patch)
tree04c1e9ad914c8c744cfd1055e2a8f6620d924c8b /src/script/common
parent738fbc66d096575bb9a1694056ce2d627a70c03d (diff)
downloadminetest-2b04ab874d75711bc021a0cd8dc7fca68f4e6929.tar.gz
minetest-2b04ab874d75711bc021a0cd8dc7fca68f4e6929.tar.bz2
minetest-2b04ab874d75711bc021a0cd8dc7fca68f4e6929.zip
SAPI: Track last executed mod and include in error messages
Diffstat (limited to 'src/script/common')
-rw-r--r--src/script/common/c_internal.cpp25
-rw-r--r--src/script/common/c_internal.h12
2 files changed, 20 insertions, 17 deletions
diff --git a/src/script/common/c_internal.cpp b/src/script/common/c_internal.cpp
index 0df0a7270..2a10ce0f2 100644
--- a/src/script/common/c_internal.cpp
+++ b/src/script/common/c_internal.cpp
@@ -79,7 +79,7 @@ int script_exception_wrapper(lua_State *L, lua_CFunction f)
* to gather a coherent backtrace. Realistically, the best we can do here is
* print which C function performed the failing pcall.
*/
-void script_error(lua_State *L, int pcall_result, const char *fxn)
+void script_error(lua_State *L, int pcall_result, const char *mod, const char *fxn)
{
if (pcall_result == 0)
return;
@@ -99,18 +99,21 @@ void script_error(lua_State *L, int pcall_result, const char *fxn)
err_type = "Unknown";
}
+ if (!mod)
+ mod = "??";
+
+ if (!fxn)
+ fxn = "??";
+
const char *err_descr = lua_tostring(L, -1);
if (!err_descr)
err_descr = "<no description>";
- std::string err_msg(err_type);
- if (fxn) {
- err_msg += " error in ";
- err_msg += fxn;
- err_msg += "(): ";
- } else {
- err_msg += " error: ";
- }
+ char buf[256];
+ snprintf(buf, sizeof(buf), "%s error from mod '%s' in callback %s(): ",
+ err_type, mod, fxn);
+
+ std::string err_msg(buf);
err_msg += err_descr;
if (pcall_result == LUA_ERRMEM) {
@@ -152,7 +155,7 @@ void script_run_callbacks_f(lua_State *L, int nargs,
int result = lua_pcall(L, nargs + 2, 1, errorhandler);
if (result != 0)
- script_error(L, result, fxn);
+ script_error(L, result, NULL, fxn);
lua_remove(L, -2); // Remove error handler
}
@@ -176,7 +179,7 @@ void log_deprecated(lua_State *L, const std::string &message)
if (doerror) {
if (L != NULL) {
- script_error(L, LUA_ERRRUN, NULL);
+ script_error(L, LUA_ERRRUN, NULL, NULL);
} else {
FATAL_ERROR("Can't do a scripterror for this deprecated message, "
"so exit completely!");
diff --git a/src/script/common/c_internal.h b/src/script/common/c_internal.h
index 54cdd7da7..ecb514c8f 100644
--- a/src/script/common/c_internal.h
+++ b/src/script/common/c_internal.h
@@ -34,11 +34,11 @@ extern "C" {
#include "common/c_types.h"
-#define PCALL_RESL(L, RES) do { \
- int result_ = (RES); \
- if (result_ != 0) { \
- script_error((L), result_, __FUNCTION__); \
- } \
+#define PCALL_RESL(L, RES) do { \
+ int result_ = (RES); \
+ if (result_ != 0) { \
+ script_error((L), result_, NULL, __FUNCTION__); \
+ } \
} while (0)
#define script_run_callbacks(L, nargs, mode) \
@@ -77,7 +77,7 @@ enum RunCallbacksMode
std::string script_get_backtrace(lua_State *L);
int script_error_handler(lua_State *L);
int script_exception_wrapper(lua_State *L, lua_CFunction f);
-void script_error(lua_State *L, int pcall_result, const char *fxn);
+void script_error(lua_State *L, int pcall_result, const char *mod, const char *fxn);
void script_run_callbacks_f(lua_State *L, int nargs,
RunCallbacksMode mode, const char *fxn);
void log_deprecated(lua_State *L, const std::string &message);