From 24853397ef4648155d886b112e00c3e2c3d1e900 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 12 Jun 2016 16:53:24 +0200 Subject: LuaState: Implemented proper locking for cCallback. --- src/Bindings/LuaChunkStay.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/Bindings/LuaChunkStay.cpp') diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp index d8d7da5d0..819e10f19 100644 --- a/src/Bindings/LuaChunkStay.cpp +++ b/src/Bindings/LuaChunkStay.cpp @@ -113,12 +113,10 @@ void cLuaChunkStay::AddChunkCoord(cLuaState & L, int a_Index) -void cLuaChunkStay::Enable(cChunkMap & a_ChunkMap, int a_OnChunkAvailableStackPos, int a_OnAllChunksAvailableStackPos) +void cLuaChunkStay::Enable(cChunkMap & a_ChunkMap, cLuaState::cCallbackPtr a_OnChunkAvailable, cLuaState::cCallbackPtr a_OnAllChunksAvailable) { - // Get the references to the callback functions: - m_LuaState = &m_Plugin.GetLuaState(); - m_OnChunkAvailable.RefStack(*m_LuaState, a_OnChunkAvailableStackPos); - m_OnAllChunksAvailable.RefStack(*m_LuaState, a_OnAllChunksAvailableStackPos); + m_OnChunkAvailable = a_OnChunkAvailable; + m_OnAllChunksAvailable = a_OnAllChunksAvailable; // Enable the ChunkStay: super::Enable(a_ChunkMap); @@ -130,10 +128,9 @@ void cLuaChunkStay::Enable(cChunkMap & a_ChunkMap, int a_OnChunkAvailableStackPo void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ) { - if (m_OnChunkAvailable.IsValid()) + if (m_OnChunkAvailable != nullptr) { - cPluginLua::cOperation Op(m_Plugin); - Op().Call(static_cast(m_OnChunkAvailable), a_ChunkX, a_ChunkZ); + m_OnChunkAvailable->Call(a_ChunkX, a_ChunkZ); } } @@ -143,15 +140,14 @@ void cLuaChunkStay::OnChunkAvailable(int a_ChunkX, int a_ChunkZ) bool cLuaChunkStay::OnAllChunksAvailable(void) { - if (m_OnAllChunksAvailable.IsValid()) + if (m_OnAllChunksAvailable != nullptr) { // Call the callback: - cPluginLua::cOperation Op(m_Plugin); - Op().Call(static_cast(m_OnAllChunksAvailable)); + m_OnAllChunksAvailable->Call(); // Remove the callback references - they won't be needed anymore - m_OnChunkAvailable.UnRef(); - m_OnAllChunksAvailable.UnRef(); + m_OnChunkAvailable.reset(); + m_OnAllChunksAvailable.reset(); } // Disable the ChunkStay by returning true -- cgit v1.2.3 From bf88312a1664311968736b4ba7ce1458c8b0954e Mon Sep 17 00:00:00 2001 From: Mattes D Date: Mon, 27 Jun 2016 20:49:59 +0200 Subject: Converted cLuaState::cCallbackPtr into a UniquePtr. --- src/Bindings/LuaChunkStay.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Bindings/LuaChunkStay.cpp') diff --git a/src/Bindings/LuaChunkStay.cpp b/src/Bindings/LuaChunkStay.cpp index 819e10f19..145a9ee1b 100644 --- a/src/Bindings/LuaChunkStay.cpp +++ b/src/Bindings/LuaChunkStay.cpp @@ -115,8 +115,8 @@ void cLuaChunkStay::AddChunkCoord(cLuaState & L, int a_Index) void cLuaChunkStay::Enable(cChunkMap & a_ChunkMap, cLuaState::cCallbackPtr a_OnChunkAvailable, cLuaState::cCallbackPtr a_OnAllChunksAvailable) { - m_OnChunkAvailable = a_OnChunkAvailable; - m_OnAllChunksAvailable = a_OnAllChunksAvailable; + m_OnChunkAvailable = std::move(a_OnChunkAvailable); + m_OnAllChunksAvailable = std::move(a_OnAllChunksAvailable); // Enable the ChunkStay: super::Enable(a_ChunkMap); -- cgit v1.2.3