diff options
author | madmaxoft <github@xoft.cz> | 2013-10-12 22:24:59 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-10-12 22:24:59 +0200 |
commit | 0352e4589882a070c5796f2604b9ad8f52a19f06 (patch) | |
tree | e92e6d56c007371a184076d1df352e9af257c278 /source/ManualBindings.cpp | |
parent | APIDump: Added pretty-printing to code examples. (diff) | |
download | cuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.tar cuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.tar.gz cuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.tar.bz2 cuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.tar.lz cuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.tar.xz cuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.tar.zst cuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.zip |
Diffstat (limited to '')
-rw-r--r-- | source/ManualBindings.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/source/ManualBindings.cpp b/source/ManualBindings.cpp index a2b4c8810..4242db46a 100644 --- a/source/ManualBindings.cpp +++ b/source/ManualBindings.cpp @@ -896,6 +896,70 @@ tolua_lerror: +class cLuaWorldTask : + public cWorld::cTask +{ +public: + cLuaWorldTask(cPluginLua & a_Plugin, int a_FnRef) : + 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_QueueTask(lua_State * tolua_S) +{ + // Binding for cWorld::QueueTask + // Params: function + + // 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"); + } + + self->QueueTask(new cLuaWorldTask(*Plugin, FnRef)); + return 0; +} + + + + + static int tolua_cPluginManager_GetAllPlugins(lua_State * tolua_S) { cPluginManager* self = (cPluginManager*) tolua_tousertype(tolua_S,1,0); @@ -2032,6 +2096,7 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S, "ForEachPlayer", tolua_ForEach< cWorld, cPlayer, &cWorld::ForEachPlayer>); tolua_function(tolua_S, "GetBlockInfo", tolua_cWorld_GetBlockInfo); tolua_function(tolua_S, "GetBlockTypeMeta", tolua_cWorld_GetBlockTypeMeta); + tolua_function(tolua_S, "QueueTask", tolua_cWorld_QueueTask); tolua_function(tolua_S, "SetSignLines", tolua_cWorld_SetSignLines); tolua_function(tolua_S, "TryGetHeight", tolua_cWorld_TryGetHeight); tolua_function(tolua_S, "UpdateSign", tolua_cWorld_SetSignLines); |