summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_util.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-08-28 12:15:12 +0200
committerGitHub <noreply@github.com>2021-08-28 12:15:12 +0200
commit6a1424f2b18520f40ba8cfd12f7988f6b33db9a6 (patch)
tree081e49b5f47693cddae8ba6c921cb6c3041b7731 /src/script/lua_api/l_util.cpp
parent0f8a6d78a72731833664b09695bd44471bc014ac (diff)
downloadminetest-6a1424f2b18520f40ba8cfd12f7988f6b33db9a6.tar.gz
minetest-6a1424f2b18520f40ba8cfd12f7988f6b33db9a6.tar.bz2
minetest-6a1424f2b18520f40ba8cfd12f7988f6b33db9a6.zip
Async-related script cleanups
Diffstat (limited to 'src/script/lua_api/l_util.cpp')
-rw-r--r--src/script/lua_api/l_util.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp
index 87436fce0..9152b5f7f 100644
--- a/src/script/lua_api/l_util.cpp
+++ b/src/script/lua_api/l_util.cpp
@@ -535,6 +535,30 @@ int ModApiUtil::l_encode_png(lua_State *L)
return 1;
}
+// get_last_run_mod()
+int ModApiUtil::l_get_last_run_mod(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+
+ lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME);
+ std::string current_mod = readParam<std::string>(L, -1, "");
+ if (current_mod.empty()) {
+ lua_pop(L, 1);
+ lua_pushstring(L, getScriptApiBase(L)->getOrigin().c_str());
+ }
+ return 1;
+}
+
+// set_last_run_mod(modname)
+int ModApiUtil::l_set_last_run_mod(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+
+ const char *mod = luaL_checkstring(L, 1);
+ getScriptApiBase(L)->setOriginDirect(mod);
+ return 0;
+}
+
void ModApiUtil::Initialize(lua_State *L, int top)
{
API_FCT(log);
@@ -574,6 +598,9 @@ void ModApiUtil::Initialize(lua_State *L, int top)
API_FCT(encode_png);
+ API_FCT(get_last_run_mod);
+ API_FCT(set_last_run_mod);
+
LuaSettings::create(L, g_settings, g_settings_path);
lua_setfield(L, top, "settings");
}
@@ -629,6 +656,9 @@ void ModApiUtil::InitializeAsync(lua_State *L, int top)
API_FCT(colorspec_to_colorstring);
API_FCT(colorspec_to_bytes);
+ API_FCT(get_last_run_mod);
+ API_FCT(set_last_run_mod);
+
LuaSettings::create(L, g_settings, g_settings_path);
lua_setfield(L, top, "settings");
}