summaryrefslogtreecommitdiffstats
path: root/src/Bindings
diff options
context:
space:
mode:
authorFeyo Korenhof <35343640+feyokorenhof@users.noreply.github.com>2021-05-26 18:07:32 +0200
committerGitHub <noreply@github.com>2021-05-26 18:07:32 +0200
commit9ddc3635d6a04ff4b78611df00c905cc86e166ae (patch)
treefa6da8cea0a2f0c9c05bb9ffa1880e25a911c6b8 /src/Bindings
parentRe-implement up/down placement metadata (#5219) (diff)
downloadcuberite-9ddc3635d6a04ff4b78611df00c905cc86e166ae.tar
cuberite-9ddc3635d6a04ff4b78611df00c905cc86e166ae.tar.gz
cuberite-9ddc3635d6a04ff4b78611df00c905cc86e166ae.tar.bz2
cuberite-9ddc3635d6a04ff4b78611df00c905cc86e166ae.tar.lz
cuberite-9ddc3635d6a04ff4b78611df00c905cc86e166ae.tar.xz
cuberite-9ddc3635d6a04ff4b78611df00c905cc86e166ae.tar.zst
cuberite-9ddc3635d6a04ff4b78611df00c905cc86e166ae.zip
Diffstat (limited to '')
-rw-r--r--src/Bindings/ManualBindings.cpp43
-rw-r--r--src/Bindings/ManualBindings.h4
2 files changed, 43 insertions, 4 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index f06f4da37..fe5a1e6cb 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -3585,6 +3585,48 @@ static int tolua_cServer_RegisterForgeMod(lua_State * a_LuaState)
+static int tolua_cServer_ScheduleTask(lua_State * a_LuaState)
+{
+ // Function signature:
+ // Server:ScheduleTask(NumTicks, Callback)
+
+ // Retrieve the args:
+ cLuaState L(a_LuaState);
+ if (
+ !L.CheckParamUserType(1, "cServer") ||
+ !L.CheckParamNumber(2) ||
+ !L.CheckParamFunction(3)
+ )
+ {
+ return 0;
+ }
+ cServer * Server;
+ int NumTicks;
+ auto Task = std::make_shared<cLuaState::cCallback>();
+ if (!L.GetStackValues(1, Server, NumTicks, Task))
+ {
+ return cManualBindings::lua_do_error(a_LuaState, "Error in function call '#funcname#': Cannot read parameters");
+ }
+ if (Server == nullptr)
+ {
+ return cManualBindings::lua_do_error(a_LuaState, "Error in function call '#funcname#': Not called on an object instance");
+ }
+ if (!Task->IsValid())
+ {
+ return cManualBindings::lua_do_error(a_LuaState, "Error in function call '#funcname#': Could not store the callback parameter");
+ }
+
+ Server->ScheduleTask(cTickTime(NumTicks), [Task](cServer & a_Server)
+ {
+ Task->Call(&a_Server);
+ });
+ return 0;
+}
+
+
+
+
+
static int tolua_cScoreboard_GetTeamNames(lua_State * L)
{
cLuaState S(L);
@@ -4625,6 +4667,7 @@ void cManualBindings::Bind(lua_State * tolua_S)
tolua_beginmodule(tolua_S, "cServer");
tolua_function(tolua_S, "RegisterForgeMod", tolua_cServer_RegisterForgeMod);
+ tolua_function(tolua_S, "ScheduleTask", tolua_cServer_ScheduleTask);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cStringCompression");
diff --git a/src/Bindings/ManualBindings.h b/src/Bindings/ManualBindings.h
index 780c6ce41..f0b7cb607 100644
--- a/src/Bindings/ManualBindings.h
+++ b/src/Bindings/ManualBindings.h
@@ -298,7 +298,3 @@ public:
return 1;
}
};
-
-
-
-