diff options
author | Mattes D <github@xoft.cz> | 2015-03-20 16:11:50 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2015-03-20 16:11:50 +0100 |
commit | 8a43da07233fd8ab59dca14b8c14668f0651624b (patch) | |
tree | 79d0fe2868b9abe1690a813a5930e996e61db15f /src/Bindings/PluginLua.cpp | |
parent | Merge pull request #1821 from bibo38/bugfix1765 (diff) | |
parent | Added cPluginLua::cResettable interface, used for scheduled tasks. (diff) | |
download | cuberite-8a43da07233fd8ab59dca14b8c14668f0651624b.tar cuberite-8a43da07233fd8ab59dca14b8c14668f0651624b.tar.gz cuberite-8a43da07233fd8ab59dca14b8c14668f0651624b.tar.bz2 cuberite-8a43da07233fd8ab59dca14b8c14668f0651624b.tar.lz cuberite-8a43da07233fd8ab59dca14b8c14668f0651624b.tar.xz cuberite-8a43da07233fd8ab59dca14b8c14668f0651624b.tar.zst cuberite-8a43da07233fd8ab59dca14b8c14668f0651624b.zip |
Diffstat (limited to 'src/Bindings/PluginLua.cpp')
-rw-r--r-- | src/Bindings/PluginLua.cpp | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 263d1f005..d133c091a 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -6,10 +6,11 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #ifdef __APPLE__ -#define LUA_USE_MACOSX + #define LUA_USE_MACOSX #else -#define LUA_USE_POSIX + #define LUA_USE_POSIX #endif + #include "PluginLua.h" #include "../CommandOutput.h" #include "PluginManager.h" @@ -52,24 +53,35 @@ cPluginLua::~cPluginLua() void cPluginLua::Close(void) { - if (m_LuaState.IsValid()) + cCSLock Lock(m_CriticalSection); + + // If already closed, bail out: + if (!m_LuaState.IsValid()) { - // Release all the references in the hook map: - for (cHookMap::iterator itrH = m_HookMap.begin(), endH = m_HookMap.end(); itrH != endH; ++itrH) - { - for (cLuaRefs::iterator itrR = itrH->second.begin(), endR = itrH->second.end(); itrR != endR; ++itrR) - { - delete *itrR; - } // for itrR - itrH->second[] - } // for itrH - m_HookMap[] - m_HookMap.clear(); - - m_LuaState.Close(); + ASSERT(m_Resettables.empty()); + ASSERT(m_HookMap.empty()); + return; } - else + + // Notify and remove all m_Resettables: + for (auto resettable: m_Resettables) { - ASSERT(m_HookMap.empty()); + resettable->Reset(); } + m_Resettables.clear(); + + // Release all the references in the hook map: + for (cHookMap::iterator itrH = m_HookMap.begin(), endH = m_HookMap.end(); itrH != endH; ++itrH) + { + for (cLuaRefs::iterator itrR = itrH->second.begin(), endR = itrH->second.end(); itrR != endR; ++itrR) + { + delete *itrR; + } // for itrR - itrH->second[] + } // for itrH - m_HookMap[] + m_HookMap.clear(); + + // Close the Lua engine: + m_LuaState.Close(); } @@ -1709,6 +1721,16 @@ int cPluginLua::CallFunctionFromForeignState( +void cPluginLua::AddResettable(cPluginLua::cResettablePtr a_Resettable) +{ + cCSLock Lock(m_CriticalSection); + m_Resettables.push_back(a_Resettable); +} + + + + + AString cPluginLua::HandleWebRequest(const HTTPRequest * a_Request) { cCSLock Lock(m_CriticalSection); @@ -1826,3 +1848,26 @@ void cPluginLua::CallbackWindowSlotChanged(int a_FnRef, cWindow & a_Window, int + +//////////////////////////////////////////////////////////////////////////////// +// cPluginLua::cResettable: + +cPluginLua::cResettable::cResettable(cPluginLua & a_Plugin): + m_Plugin(&a_Plugin), + m_CSPlugin(a_Plugin.m_CriticalSection) +{ +} + + + + + +void cPluginLua::cResettable::Reset(void) +{ + cCSLock Lock(m_CSPlugin); + m_Plugin = nullptr; +} + + + + |