summaryrefslogtreecommitdiffstats
path: root/src/Bindings
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-01-14 21:17:03 +0100
committerTycho <work.tycho+git@gmail.com>2014-01-14 21:17:03 +0100
commit292ccdc09e083d6c0af02328651ef3d99cd8edb6 (patch)
tree3300fbe00f3b8fdca7dccb9a912bf79a1a841f2e /src/Bindings
parentCMake: Release profile build inherits from Release, not Debug. (diff)
downloadcuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.tar
cuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.tar.gz
cuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.tar.bz2
cuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.tar.lz
cuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.tar.xz
cuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.tar.zst
cuberite-292ccdc09e083d6c0af02328651ef3d99cd8edb6.zip
Diffstat (limited to 'src/Bindings')
-rw-r--r--src/Bindings/ManualBindings.cpp62
1 files changed, 58 insertions, 4 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index a9368f613..b12fa5f03 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -941,10 +941,6 @@ protected:
}
} ;
-
-
-
-
static int tolua_cWorld_QueueTask(lua_State * tolua_S)
{
// Binding for cWorld::QueueTask
@@ -980,7 +976,65 @@ static int tolua_cWorld_QueueTask(lua_State * tolua_S)
return 0;
}
+class cLuaScheduledWorldTask :
+ public cWorld::cScheduledTask
+{
+public:
+ cLuaScheduledWorldTask(cPluginLua & a_Plugin, int a_FnRef, int a_Ticks) :
+ cScheduledTask(a_Ticks),
+ m_Plugin(a_Plugin),
+ m_FnRef(a_FnRef)
+ {
+ }
+
+protected:
+ cPluginLua & m_Plugin;
+ int m_FnRef;
+
+ // cWorld::cTask overrides:
+ virtual void Run(cWorld & a_World) override
+ {
+ m_Plugin.Call(m_FnRef, &a_World);
+ }
+};
+
+
+static int tolua_cWorld_ScheduleTask(lua_State * tolua_S)
+{
+ // Binding for cWorld::ScheduleTask
+ // Params: function, Ticks
+
+ // Retrieve the cPlugin from the LuaState:
+ cPluginLua * Plugin = GetLuaPlugin(tolua_S);
+ if (Plugin == NULL)
+ {
+ // An error message has been already printed in GetLuaPlugin()
+ return 0;
+ }
+
+ // Retrieve the args:
+ cWorld * self = (cWorld *)tolua_tousertype(tolua_S, 1, 0);
+ if (self == NULL)
+ {
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance");
+ }
+ if (!lua_isfunction(tolua_S, 2))
+ {
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #1");
+ }
+
+ // Create a reference to the function:
+ int FnRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX);
+ if (FnRef == LUA_REFNIL)
+ {
+ return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #1");
+ }
+
+ int Ticks = (int) tolua_tonumber (tolua_S, 3, 0);
+ self->ScheduleTask(new cLuaScheduledWorldTask(*Plugin, FnRef,Ticks));
+ return 0;
+}