From f3a0fed72427e747d2c8c9599dd8279ff598dc28 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 21 Aug 2013 21:29:30 +0200 Subject: Hook adding uses the new API. Multiple hooks per plugin can be added. The cPluginManager.AddHook() has four available signatures, the recommended one is cPluginManager.AddHook(HOOK_TYPE, CallbackFunction) --- source/PluginLua.h | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'source/PluginLua.h') diff --git a/source/PluginLua.h b/source/PluginLua.h index 300fadc8b..877de2274 100644 --- a/source/PluginLua.h +++ b/source/PluginLua.h @@ -100,7 +100,7 @@ public: virtual void ClearConsoleCommands(void) override; - virtual bool CanAddHook(cPluginManager::PluginHook a_Hook) override; + virtual bool CanAddHook(int a_Hook) override; // cWebPlugin override virtual const AString GetWebTitle(void) const {return GetName(); } @@ -128,18 +128,35 @@ public: /// Calls the plugin-specified "cLuaWindow slot changed" callback. void CallbackWindowSlotChanged(int a_FnRef, cWindow & a_Window, int a_SlotNum); -protected: - cCriticalSection m_CriticalSection; - cLuaState m_LuaState; + /// Returns the name of Lua function that should handle the specified hook type in the older (#121) API + static const char * GetHookFnName(int a_HookType); + /** Adds a Lua function to be called for the specified hook. + The function has to be on the Lua stack at the specified index a_FnRefIdx + Returns true if the hook was added successfully. + */ + bool AddHookRef(int a_HookType, int a_FnRefIdx); + +protected: /// Maps command name into Lua function reference typedef std::map CommandMap; + /// Provides an array of Lua function references + typedef std::vector cLuaRefs; + + /// Maps hook types into arrays of Lua function references to call for each hook type + typedef std::map cHookMap; + + cCriticalSection m_CriticalSection; + cLuaState m_LuaState; + CommandMap m_Commands; CommandMap m_ConsoleCommands; - - /// Returns the name of Lua function that should handle the specified hook - const char * GetHookFnName(cPluginManager::PluginHook a_Hook); + + cHookMap m_HookMap; + + /// Releases all Lua references and closes the LuaState + void Close(void); } ; // tolua_export -- cgit v1.2.3