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 From 7eae58281a1c912f298ac8d5f463a2c60cdc2440 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 22 Aug 2013 21:03:20 +0200 Subject: Fixed AddHook() wanting old-style function names. Error reported by STR_Warrior in the forum http://forum.mc-server.org/showthread.php?tid=1227&pid=9620#pid9620 --- source/PluginLua.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source/PluginLua.h') diff --git a/source/PluginLua.h b/source/PluginLua.h index 877de2274..fee9c4986 100644 --- a/source/PluginLua.h +++ b/source/PluginLua.h @@ -100,7 +100,8 @@ public: virtual void ClearConsoleCommands(void) override; - virtual bool CanAddHook(int a_Hook) override; + /// Returns true if the plugin contains the function for the specified hook type, using the old-style registration (#121) + bool CanAddOldStyleHook(int a_HookType); // cWebPlugin override virtual const AString GetWebTitle(void) const {return GetName(); } -- cgit v1.2.3