summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_server.cpp
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/lua_api/l_server.cpp
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/lua_api/l_server.cpp')
-rw-r--r--src/script/lua_api/l_server.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp
index 96c0327df..73eca9d60 100644
--- a/src/script/lua_api/l_server.cpp
+++ b/src/script/lua_api/l_server.cpp
@@ -438,6 +438,31 @@ int ModApiServer::l_notify_authentication_modified(lua_State *L)
return 0;
}
+// get_last_run_mod()
+int ModApiServer::l_get_last_run_mod(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ lua_getfield(L, LUA_REGISTRYINDEX, SCRIPT_MOD_NAME_FIELD);
+ const char *current_mod = lua_tostring(L, -1);
+ if (current_mod == NULL || current_mod[0] == '\0') {
+ lua_pop(L, 1);
+ lua_pushstring(L, getScriptApiBase(L)->getOrigin().c_str());
+ }
+ return 1;
+}
+
+// set_last_run_mod(modname)
+int ModApiServer::l_set_last_run_mod(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+#ifdef SCRIPTAPI_DEBUG
+ const char *mod = lua_tostring(L, 1);
+ getScriptApiBase(L)->setOriginDirect(mod);
+ //printf(">>>> last mod set from Lua: %s\n", mod);
+#endif
+ return 0;
+}
+
#ifndef NDEBUG
// cause_error(type_of_error)
int ModApiServer::l_cause_error(lua_State *L)
@@ -495,6 +520,8 @@ void ModApiServer::Initialize(lua_State *L, int top)
API_FCT(unban_player_or_ip);
API_FCT(notify_authentication_modified);
+ API_FCT(get_last_run_mod);
+ API_FCT(set_last_run_mod);
#ifndef NDEBUG
API_FCT(cause_error);
#endif