diff options
Diffstat (limited to 'src/Bindings')
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 43 | ||||
-rw-r--r-- | src/Bindings/ManualBindings.h | 4 |
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; } }; - - - - |