diff options
author | madmaxoft <github@xoft.cz> | 2014-02-09 18:56:16 +0100 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-02-09 18:56:16 +0100 |
commit | 9455f59b1100f3db2c5b1e88bb9d1f6a01664721 (patch) | |
tree | 5a6fcca8728b60dc357baf104009eae1bccdb4d4 /src/Bindings | |
parent | cLuaState::cRef can be unbound and re-bound. (diff) | |
download | cuberite-9455f59b1100f3db2c5b1e88bb9d1f6a01664721.tar cuberite-9455f59b1100f3db2c5b1e88bb9d1f6a01664721.tar.gz cuberite-9455f59b1100f3db2c5b1e88bb9d1f6a01664721.tar.bz2 cuberite-9455f59b1100f3db2c5b1e88bb9d1f6a01664721.tar.lz cuberite-9455f59b1100f3db2c5b1e88bb9d1f6a01664721.tar.xz cuberite-9455f59b1100f3db2c5b1e88bb9d1f6a01664721.tar.zst cuberite-9455f59b1100f3db2c5b1e88bb9d1f6a01664721.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/AllToLua.pkg | 2 | ||||
-rw-r--r-- | src/Bindings/LuaChunkStay.cpp | 52 | ||||
-rw-r--r-- | src/Bindings/LuaChunkStay.h | 58 |
3 files changed, 112 insertions, 0 deletions
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index f65aed9bb..a78ee7d56 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -24,6 +24,7 @@ $cfile "Plugin.h" $cfile "PluginLua.h" $cfile "WebPlugin.h" $cfile "LuaWindow.h" +$cfile "LuaChunkStay.h" $cfile "../BlockID.h" $cfile "../StringUtils.h" @@ -70,6 +71,7 @@ $cfile "../Generating/ChunkDesc.h" $cfile "../CraftingRecipes.h" $cfile "../UI/Window.h" $cfile "../Mobs/Monster.h" +$cfile "../ChunkStay.h" diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp new file mode 100644 index 000000000..606f7694f --- /dev/null +++ b/src/Bindings/LuaChunkStay.cpp @@ -0,0 +1,52 @@ + +// LuaChunkStay.cpp + +// Implements the cLuaChunkStay class representing a cChunkStay binding for plugins + +#include "Globals.h" +#include "LuaChunkStay.h" +#include "../World.h" + + + + + +void cLuaChunkStay::Enable( + cWorld & a_World, cLuaState & a_LuaState, + const cLuaState::cRef & a_OnChunkAvailable, const cLuaState::cRef & a_OnAllChunksAvailable +) +{ + if (m_LuaState != NULL) + { + LOGWARNING("LuaChunkStay: Already enabled. Ignoring this call."); + a_LuaState.LogStackTrace(); + return; + } + m_LuaState = &a_LuaState; + m_OnChunkAvailable = a_OnAllChunksAvailable; + m_OnAllChunksAvailable = a_OnAllChunksAvailable; + super::Enable(*a_World.GetChunkMap()); +} + + + + + +void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ) +{ + m_LuaState->Call(m_OnChunkAvailable, a_ChunkX, a_ChunkZ); +} + + + + + +void cLuaChunkStay::OnAllChunksAvailable(void) +{ + m_LuaState->Call(m_OnAllChunksAvailable); +} + + + + + diff --git a/src/Bindings/LuaChunkStay.h b/src/Bindings/LuaChunkStay.h new file mode 100644 index 000000000..e9d87d7f6 --- /dev/null +++ b/src/Bindings/LuaChunkStay.h @@ -0,0 +1,58 @@ + +// LuaChunkStay.h + +// Declares the cLuaChunkStay class representing a cChunkStay binding for plugins + + + + + +#pragma once + +#include "LuaState.h" +#include "../ChunkStay.h" + + + + + +// tolua_begin +class cLuaChunkStay + : public cChunkStay +{ + typedef cChunkStay super; + +public: + // Allow Lua to construct objects of this class: + cLuaChunkStay(void) {} + + // Allow Lua to garbage-collect objects of this class: + ~cLuaChunkStay() {} + + // tolua_end + + /** Enabled the ChunkStay for the specified world, with the specified Lua callbacks. + Exported in ManualBindings. */ + void Enable( + cWorld & a_World, cLuaState & a_LuaState, + const cLuaState::cRef & a_OnChunkAvailable, const cLuaState::cRef & a_OnAllChunksAvailable + ); + +protected: + /** The Lua state associated with the callbacks. Only valid when enabled. */ + cLuaState * m_LuaState; + + /** The Lua function to call in OnChunkAvailable. Only valid when enabled. */ + cLuaState::cRef m_OnChunkAvailable; + + /** The Lua function to call in OnAllChunksAvailable. Only valid when enabled. */ + cLuaState::cRef m_OnAllChunksAvailable; + + // cChunkStay overrides: + virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override; + virtual void OnAllChunksAvailable(void) override; +} ; // tolua_export + + + + |