summaryrefslogtreecommitdiffstats
path: root/src/Bindings/LuaChunkStay.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-02-09 20:39:45 +0100
committermadmaxoft <github@xoft.cz>2014-02-09 20:39:45 +0100
commit47a497fa895fa5f353ba593d4bb232ea514e66c9 (patch)
tree59be3c7320d5c4f8b8d25aa2a28769e66de8921b /src/Bindings/LuaChunkStay.cpp
parentDebuggers: Disabled testing plugin calls. (diff)
downloadcuberite-47a497fa895fa5f353ba593d4bb232ea514e66c9.tar
cuberite-47a497fa895fa5f353ba593d4bb232ea514e66c9.tar.gz
cuberite-47a497fa895fa5f353ba593d4bb232ea514e66c9.tar.bz2
cuberite-47a497fa895fa5f353ba593d4bb232ea514e66c9.tar.lz
cuberite-47a497fa895fa5f353ba593d4bb232ea514e66c9.tar.xz
cuberite-47a497fa895fa5f353ba593d4bb232ea514e66c9.tar.zst
cuberite-47a497fa895fa5f353ba593d4bb232ea514e66c9.zip
Diffstat (limited to 'src/Bindings/LuaChunkStay.cpp')
-rw-r--r--src/Bindings/LuaChunkStay.cpp45
1 files changed, 36 insertions, 9 deletions
diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp
index 606f7694f..f84964f56 100644
--- a/src/Bindings/LuaChunkStay.cpp
+++ b/src/Bindings/LuaChunkStay.cpp
@@ -11,20 +11,29 @@
+cLuaChunkStay::cLuaChunkStay(void) :
+ m_LuaState((lua_State *)NULL) // Want a detached Lua state by default
+{
+}
+
+
+
+
+
void cLuaChunkStay::Enable(
- cWorld & a_World, cLuaState & a_LuaState,
- const cLuaState::cRef & a_OnChunkAvailable, const cLuaState::cRef & a_OnAllChunksAvailable
+ cWorld & a_World, lua_State * a_LuaState,
+ int a_OnChunkAvailableStackPos, int a_OnAllChunksAvailableStackPos
)
{
- if (m_LuaState != NULL)
+ if (m_LuaState.IsValid())
{
LOGWARNING("LuaChunkStay: Already enabled. Ignoring this call.");
- a_LuaState.LogStackTrace();
+ cLuaState::LogStackTrace(a_LuaState);
return;
}
- m_LuaState = &a_LuaState;
- m_OnChunkAvailable = a_OnAllChunksAvailable;
- m_OnAllChunksAvailable = a_OnAllChunksAvailable;
+ m_LuaState.Attach(a_LuaState);
+ m_OnChunkAvailable.RefStack(m_LuaState, a_OnChunkAvailableStackPos);
+ m_OnAllChunksAvailable.RefStack(m_LuaState, a_OnAllChunksAvailableStackPos);
super::Enable(*a_World.GetChunkMap());
}
@@ -32,9 +41,27 @@ void cLuaChunkStay::Enable(
+void cLuaChunkStay::Disable(void)
+{
+ super::Disable();
+
+ // If the state was valid (bound to Lua functions), unbind those functions:
+ if (!m_LuaState.IsValid())
+ {
+ return;
+ }
+ m_OnAllChunksAvailable.UnRef();
+ m_OnChunkAvailable.UnRef();
+ m_LuaState.Detach();
+}
+
+
+
+
+
void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ)
{
- m_LuaState->Call(m_OnChunkAvailable, a_ChunkX, a_ChunkZ);
+ m_LuaState.Call(m_OnChunkAvailable, a_ChunkX, a_ChunkZ);
}
@@ -43,7 +70,7 @@ void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ)
void cLuaChunkStay::OnAllChunksAvailable(void)
{
- m_LuaState->Call(m_OnAllChunksAvailable);
+ m_LuaState.Call(m_OnAllChunksAvailable);
}