summaryrefslogtreecommitdiff
path: root/src/script/cpp_api
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2018-06-06 12:53:59 +0200
committerGitHub <noreply@github.com>2018-06-06 12:53:59 +0200
commitccc3af128cb4b6213b8111115c570fe988d3523b (patch)
tree38a2f8cb43018759ca234ef1de62a43ff5049704 /src/script/cpp_api
parenta2de439a91df6876e13230696c05957a9da8b2ce (diff)
downloadminetest-ccc3af128cb4b6213b8111115c570fe988d3523b.tar.gz
minetest-ccc3af128cb4b6213b8111115c570fe988d3523b.tar.bz2
minetest-ccc3af128cb4b6213b8111115c570fe988d3523b.zip
CSM/SSM: Add on_mods_loaded callback (#7411)
* CSM/SSM: Add on_mods_loaded callback
Diffstat (limited to 'src/script/cpp_api')
-rw-r--r--src/script/cpp_api/s_client.cpp11
-rw-r--r--src/script/cpp_api/s_client.h3
-rw-r--r--src/script/cpp_api/s_server.cpp11
-rw-r--r--src/script/cpp_api/s_server.h3
4 files changed, 28 insertions, 0 deletions
diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp
index a8d8c2de4..7be4fc6a9 100644
--- a/src/script/cpp_api/s_client.cpp
+++ b/src/script/cpp_api/s_client.cpp
@@ -25,6 +25,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "common/c_content.h"
#include "s_item.h"
+void ScriptApiClient::on_mods_loaded()
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get registered shutdown hooks
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_mods_loaded");
+ // Call callbacks
+ runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
+}
+
void ScriptApiClient::on_shutdown()
{
SCRIPTAPI_PRECHECKHEADER
diff --git a/src/script/cpp_api/s_client.h b/src/script/cpp_api/s_client.h
index 402b44e33..93fe96791 100644
--- a/src/script/cpp_api/s_client.h
+++ b/src/script/cpp_api/s_client.h
@@ -37,6 +37,9 @@ class ClientEnvironment;
class ScriptApiClient : virtual public ScriptApiBase
{
public:
+ // Calls when mods are loaded
+ void on_mods_loaded();
+
// Calls on_shutdown handlers
void on_shutdown();
diff --git a/src/script/cpp_api/s_server.cpp b/src/script/cpp_api/s_server.cpp
index 38bd41f87..b0459fbfa 100644
--- a/src/script/cpp_api/s_server.cpp
+++ b/src/script/cpp_api/s_server.cpp
@@ -147,6 +147,17 @@ bool ScriptApiServer::on_chat_message(const std::string &name,
return ate;
}
+void ScriptApiServer::on_mods_loaded()
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ // Get registered shutdown hooks
+ lua_getglobal(L, "core");
+ lua_getfield(L, -1, "registered_on_mods_loaded");
+ // Call callbacks
+ runCallbacks(0, RUN_CALLBACKS_MODE_FIRST);
+}
+
void ScriptApiServer::on_shutdown()
{
SCRIPTAPI_PRECHECKHEADER
diff --git a/src/script/cpp_api/s_server.h b/src/script/cpp_api/s_server.h
index 74de19bee..769939d3f 100644
--- a/src/script/cpp_api/s_server.h
+++ b/src/script/cpp_api/s_server.h
@@ -30,6 +30,9 @@ public:
// Returns true if script handled message
bool on_chat_message(const std::string &name, const std::string &message);
+ // Calls when mods are loaded
+ void on_mods_loaded();
+
// Calls on_shutdown handlers
void on_shutdown();