aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
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
parent0f8a6d78a72731833664b09695bd44471bc014ac (diff)
downloadminetest-6a1424f2b18520f40ba8cfd12f7988f6b33db9a6.tar.gz
minetest-6a1424f2b18520f40ba8cfd12f7988f6b33db9a6.tar.bz2
minetest-6a1424f2b18520f40ba8cfd12f7988f6b33db9a6.zip
Async-related script cleanups
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_mainmenu.cpp11
-rw-r--r--src/script/lua_api/l_server.cpp29
-rw-r--r--src/script/lua_api/l_server.h6
-rw-r--r--src/script/lua_api/l_util.cpp30
-rw-r--r--src/script/lua_api/l_util.h6
5 files changed, 43 insertions, 39 deletions
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index ad00de1c4..6e9a5c34f 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "lua_api/l_internal.h"
#include "common/c_content.h"
#include "cpp_api/s_async.h"
+#include "scripting_mainmenu.h"
#include "gui/guiEngine.h"
#include "gui/guiMainMenu.h"
#include "gui/guiKeyChangeMenu.h"
@@ -816,20 +817,20 @@ int ModApiMainMenu::l_open_dir(lua_State *L)
/******************************************************************************/
int ModApiMainMenu::l_do_async_callback(lua_State *L)
{
- GUIEngine* engine = getGuiEngine(L);
+ MainMenuScripting *script = getScriptApi<MainMenuScripting>(L);
size_t func_length, param_length;
const char* serialized_func_raw = luaL_checklstring(L, 1, &func_length);
-
const char* serialized_param_raw = luaL_checklstring(L, 2, &param_length);
sanity_check(serialized_func_raw != NULL);
sanity_check(serialized_param_raw != NULL);
- std::string serialized_func = std::string(serialized_func_raw, func_length);
- std::string serialized_param = std::string(serialized_param_raw, param_length);
+ u32 jobId = script->queueAsync(
+ std::string(serialized_func_raw, func_length),
+ std::string(serialized_param_raw, param_length));
- lua_pushinteger(L, engine->queueAsync(serialized_func, serialized_param));
+ lua_pushinteger(L, jobId);
return 1;
}
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp
index bf5292521..9866e0bc8 100644
--- a/src/script/lua_api/l_server.cpp
+++ b/src/script/lua_api/l_server.cpp
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "common/c_content.h"
#include "cpp_api/s_base.h"
#include "cpp_api/s_security.h"
+#include "scripting_server.h"
#include "server.h"
#include "environment.h"
#include "remoteplayer.h"
@@ -498,31 +499,6 @@ 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_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 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;
-}
-
void ModApiServer::Initialize(lua_State *L, int top)
{
API_FCT(request_shutdown);
@@ -555,7 +531,4 @@ void ModApiServer::Initialize(lua_State *L, int top)
API_FCT(remove_player);
API_FCT(unban_player_or_ip);
API_FCT(notify_authentication_modified);
-
- API_FCT(get_last_run_mod);
- API_FCT(set_last_run_mod);
}
diff --git a/src/script/lua_api/l_server.h b/src/script/lua_api/l_server.h
index 2df180b17..fb7a851f4 100644
--- a/src/script/lua_api/l_server.h
+++ b/src/script/lua_api/l_server.h
@@ -103,12 +103,6 @@ private:
// notify_authentication_modified(name)
static int l_notify_authentication_modified(lua_State *L);
- // get_last_run_mod()
- static int l_get_last_run_mod(lua_State *L);
-
- // set_last_run_mod(modname)
- static int l_set_last_run_mod(lua_State *L);
-
public:
static void Initialize(lua_State *L, int top);
};
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");
}
diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h
index 54d2be619..cc91e8d39 100644
--- a/src/script/lua_api/l_util.h
+++ b/src/script/lua_api/l_util.h
@@ -110,6 +110,12 @@ private:
// encode_png(w, h, data, level)
static int l_encode_png(lua_State *L);
+ // get_last_run_mod()
+ static int l_get_last_run_mod(lua_State *L);
+
+ // set_last_run_mod(modname)
+ static int l_set_last_run_mod(lua_State *L);
+
public:
static void Initialize(lua_State *L, int top);
static void InitializeAsync(lua_State *L, int top);