diff --git a/ElunaBinding.h b/ElunaBinding.h index 693afc2..d200967 100644 --- a/ElunaBinding.h +++ b/ElunaBinding.h @@ -30,7 +30,8 @@ public: functionReference(funcRef), isTemporary(shots != 0), remainingShots(shots) - {} + { + } }; typedef std::vector FunctionRefVector; typedef UNORDERED_MAP EventToFunctionsMap; @@ -49,9 +50,6 @@ public: // unregisters all registered functions and clears all registered events from the bindings virtual void Clear() { }; - - // Updates the counters on all temporary bindings and erases them if the counter would reach 0. - virtual void UpdateTemporaryBindings() { }; }; template @@ -74,35 +72,29 @@ public: Bindings.clear(); } - void UpdateTemporaryBindings() override + // Pushes the function references and updates the counters on the binds and erases them if the counter would reach 0 + void PushFuncRefs(lua_State* L, int event_id) { - for (EventToFunctionsMap::iterator itr = Bindings.begin(); itr != Bindings.end();) + for (FunctionRefVector::iterator it = Bindings[event_id].begin(); it != Bindings[event_id].end();) { - for (FunctionRefVector::iterator it = itr->second.begin(); it != itr->second.end();) - { - Binding &b = (*it); - if (b.isTemporary && b.remainingShots == 0) - { - luaL_unref(E.L, LUA_REGISTRYINDEX, b.functionReference); - it = itr->second.erase(it); - } - else - { - it++; - } - } + FunctionRefVector::iterator it_old = it++; - // If there are no more entries in the vector, erase the vector. - if (itr->second.empty()) + lua_rawgeti(L, LUA_REGISTRYINDEX, (it_old->functionReference)); + + if (it_old->isTemporary) { - itr = Bindings.erase(itr); - } - else - { - itr++; + --it_old->remainingShots; + if (it_old->remainingShots == 0) + { + luaL_unref(L, LUA_REGISTRYINDEX, it_old->functionReference); + Bindings[event_id].erase(it_old); + } } } - } + + if (Bindings[event_id].empty()) + Bindings.erase(event_id); + }; void Insert(int eventId, int funcRef, uint32 shots) // Inserts a new registered event { @@ -148,48 +140,32 @@ public: Bindings.clear(); } - void UpdateTemporaryBindings() override + // Pushes the function references and updates the counters on the binds and erases them if the counter would reach 0 + void PushFuncRefs(lua_State* L, int event_id, uint32 entry) { - for (EntryToEventsMap::iterator itr = Bindings.begin(); itr != Bindings.end();) + for (FunctionRefVector::iterator it = Bindings[entry][event_id].begin(); it != Bindings[entry][event_id].end();) { - for (EventToFunctionsMap::iterator it = itr->second.begin(); it != itr->second.end();) - { - for (FunctionRefVector::iterator i = it->second.begin(); i != it->second.end();) - { - Binding &b = (*i); - if (b.isTemporary && b.remainingShots == 0) - { - luaL_unref(E.L, LUA_REGISTRYINDEX, b.functionReference); - i = it->second.erase(i); - } - else - { - i++; - } - } + FunctionRefVector::iterator it_old = it++; - // If there are no more entries in the vector, erase the vector. - if (it->second.empty()) - { - it = itr->second.erase(it); - } - else - { - it++; - } - } + lua_rawgeti(L, LUA_REGISTRYINDEX, (it_old->functionReference)); - // If there are no more vector in the map, erase the map. - if (itr->second.empty()) + if (it_old->isTemporary) { - itr = Bindings.erase(itr); - } - else - { - itr++; + --it_old->remainingShots; + if (it_old->remainingShots == 0) + { + luaL_unref(L, LUA_REGISTRYINDEX, it_old->functionReference); + Bindings[entry][event_id].erase(it_old); + } } } - } + + if (Bindings[entry][event_id].empty()) + Bindings[entry].erase(event_id); + + if (Bindings[entry].empty()) + Bindings.erase(entry); + }; void Insert(uint32 entryId, int eventId, int funcRef, uint32 shots) // Inserts a new registered event { diff --git a/GlobalMethods.h b/GlobalMethods.h index 4a0f788..5f08647 100644 --- a/GlobalMethods.h +++ b/GlobalMethods.h @@ -471,47 +471,33 @@ namespace LuaGlobalFunctions return 1; } - /** - * Registers a packet event - * - *
-     * enum PacketEvents
-     * {
-     *     PACKET_EVENT_ON_PACKET_RECEIVE          =     5,
-     *     PACKET_EVENT_ON_PACKET_RECEIVE_UNKNOWN  =     6,
-     *     PACKET_EVENT_ON_PACKET_SEND             =     7,
-     *
-     *     PACKET_EVENT_COUNT
-     * };
-     * 
- * - * @param uint32 entry : opcode - * @param uint32 event : packet event Id, refer to PacketEvents above - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * @param function function : function to register - */ - int RegisterPacketEvent(Eluna* E, lua_State* L) + void RegisterEntryHelper(Eluna* E, lua_State* L, int regtype) { uint32 entry = Eluna::CHECKVAL(L, 1); uint32 ev = Eluna::CHECKVAL(L, 2); - uint32 shots; - - if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility. - { - shots = 0; - lua_pushvalue(L, 3); - } - else // Otherwise, shots is the third argument and the function must be the fourth. - { - shots = Eluna::CHECKVAL(L, 3); - luaL_checktype(L, 4, LUA_TFUNCTION); - lua_pushvalue(L, 4); - } + luaL_checktype(L, 3, LUA_TFUNCTION); + lua_pushvalue(L, 3); + uint32 shots = Eluna::CHECKVAL(L, 4, 0); int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); - if (functionRef > 0) - E->Register(HookMgr::REGTYPE_PACKET, entry, ev, functionRef, shots); - return 0; + if (luaL_ref(L, LUA_REGISTRYINDEX) >= 0) + E->Register(regtype, entry, ev, functionRef, shots); + else + luaL_argerror(L, 3, "unable to make a ref to function"); + } + + void RegisterEventHelper(Eluna* E, lua_State* L, int regtype) + { + uint32 ev = Eluna::CHECKVAL(L, 1); + luaL_checktype(L, 2, LUA_TFUNCTION); + lua_pushvalue(L, 2); + uint32 shots = Eluna::CHECKVAL(L, 3, 0); + + int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); + if (luaL_ref(L, LUA_REGISTRYINDEX) >= 0) + E->Register(regtype, 0, ev, functionRef, shots); + else + luaL_argerror(L, 2, "unable to make a ref to function"); } /** @@ -575,29 +561,12 @@ namespace LuaGlobalFunctions * * * @param uint32 event : server event Id, refer to ServerEvents above - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" * @param function function : function to register + * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" */ int RegisterServerEvent(Eluna* E, lua_State* L) { - uint32 ev = Eluna::CHECKVAL(L, 1); - uint32 shots; - - if (lua_isfunction(L, 2)) // If the second argument is a function, set shots to 0 for backwards-compatibility. - { - shots = 0; - lua_pushvalue(L, 2); - } - else // Otherwise, shots is the second argument and the function must be the third. - { - shots = Eluna::CHECKVAL(L, 2); - luaL_checktype(L, 3, LUA_TFUNCTION); - lua_pushvalue(L, 3); - } - - int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); - if (functionRef > 0) - E->Register(HookMgr::REGTYPE_SERVER, 0, ev, functionRef, shots); + RegisterEventHelper(E, L, HookMgr::REGTYPE_SERVER); return 0; } @@ -657,29 +626,12 @@ namespace LuaGlobalFunctions * * * @param uint32 event : [Player] event Id, refer to PlayerEvents above - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" * @param function function : function to register + * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" */ int RegisterPlayerEvent(Eluna* E, lua_State* L) { - uint32 ev = Eluna::CHECKVAL(L, 1); - uint32 shots; - - if (lua_isfunction(L, 2)) // If the second argument is a function, set shots to 0 for backwards-compatibility. - { - shots = 0; - lua_pushvalue(L, 2); - } - else // Otherwise, shots is the second argument and the function must be the third. - { - shots = Eluna::CHECKVAL(L, 2); - luaL_checktype(L, 3, LUA_TFUNCTION); - lua_pushvalue(L, 3); - } - - int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); - if (functionRef > 0) - E->Register(HookMgr::REGTYPE_PLAYER, 0, ev, functionRef, shots); + RegisterEventHelper(E, L, HookMgr::REGTYPE_PLAYER); return 0; } @@ -707,29 +659,12 @@ namespace LuaGlobalFunctions * * * @param uint32 event : [Guild] event Id, refer to GuildEvents above - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" * @param function function : function to register + * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" */ int RegisterGuildEvent(Eluna* E, lua_State* L) { - uint32 ev = Eluna::CHECKVAL(L, 1); - uint32 shots; - - if (lua_isfunction(L, 2)) // If the second argument is a function, set shots to 0 for backwards-compatibility. - { - shots = 0; - lua_pushvalue(L, 2); - } - else // Otherwise, shots is the second argument and the function must be the third. - { - shots = Eluna::CHECKVAL(L, 2); - luaL_checktype(L, 3, LUA_TFUNCTION); - lua_pushvalue(L, 3); - } - - int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); - if (functionRef > 0) - E->Register(HookMgr::REGTYPE_GUILD, 0, ev, functionRef, shots); + RegisterEventHelper(E, L, HookMgr::REGTYPE_GUILD); return 0; } @@ -752,29 +687,61 @@ namespace LuaGlobalFunctions * * * @param uint32 event : [Group] event Id, refer to GroupEvents above - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" * @param function function : function to register + * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" */ int RegisterGroupEvent(Eluna* E, lua_State* L) { - uint32 ev = Eluna::CHECKVAL(L, 1); - uint32 shots; + RegisterEventHelper(E, L, HookMgr::REGTYPE_GROUP); + return 0; + } - if (lua_isfunction(L, 2)) // If the second argument is a function, set shots to 0 for backwards-compatibility. - { - shots = 0; - lua_pushvalue(L, 2); - } - else // Otherwise, shots is the second argument and the function must be the third. - { - shots = Eluna::CHECKVAL(L, 2); - luaL_checktype(L, 3, LUA_TFUNCTION); - lua_pushvalue(L, 3); - } + /** + * Registers a [Battleground] event + * + *
+     * enum BGEvents
+     * {
+     *     BG_EVENT_ON_START                               = 1,    // (event, bg, bgId, instanceId) - Needs to be added to TC
+     *     BG_EVENT_ON_END                                 = 2,    // (event, bg, bgId, instanceId, winner) - Needs to be added to TC
+     *     BG_EVENT_ON_CREATE                              = 3,    // (event, bg, bgId, instanceId) - Needs to be added to TC
+     *     BG_EVENT_ON_PRE_DESTROY                         = 4,    // (event, bg, bgId, instanceId) - Needs to be added to TC
+     *     BG_EVENT_COUNT
+     * };
+     * 
+ * + * @param uint32 event : [Battleground] event Id, refer to BGEvents above + * @param function function : function to register + * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" + */ + int RegisterBGEvent(Eluna* E, lua_State* L) + { + RegisterEventHelper(E, L, HookMgr::REGTYPE_BG); + return 0; + } - int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); - if (functionRef > 0) - E->Register(HookMgr::REGTYPE_GROUP, 0, ev, functionRef, shots); + /** + * Registers a packet event + * + *
+     * enum PacketEvents
+     * {
+     *     PACKET_EVENT_ON_PACKET_RECEIVE          =     5,
+     *     PACKET_EVENT_ON_PACKET_RECEIVE_UNKNOWN  =     6,
+     *     PACKET_EVENT_ON_PACKET_SEND             =     7,
+     *
+     *     PACKET_EVENT_COUNT
+     * };
+     * 
+ * + * @param uint32 entry : opcode + * @param uint32 event : packet event Id, refer to PacketEvents above + * @param function function : function to register + * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" + */ + int RegisterPacketEvent(Eluna* E, lua_State* L) + { + RegisterEntryHelper(E, L, HookMgr::REGTYPE_PACKET); return 0; } @@ -792,30 +759,12 @@ namespace LuaGlobalFunctions * * @param uint32 menu_id : [Creature] entry Id * @param uint32 event : [Creature] gossip event Id, refer to GossipEvents above - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" * @param function function : function to register + * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" */ int RegisterCreatureGossipEvent(Eluna* E, lua_State* L) { - uint32 entry = Eluna::CHECKVAL(L, 1); - uint32 ev = Eluna::CHECKVAL(L, 2); - uint32 shots; - - if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility. - { - shots = 0; - lua_pushvalue(L, 3); - } - else // Otherwise, shots is the third argument and the function must be the fourth. - { - shots = Eluna::CHECKVAL(L, 3); - luaL_checktype(L, 4, LUA_TFUNCTION); - lua_pushvalue(L, 4); - } - - int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); - if (functionRef > 0) - E->Register(HookMgr::REGTYPE_CREATURE_GOSSIP, entry, ev, functionRef, shots); + RegisterEntryHelper(E, L, HookMgr::REGTYPE_CREATURE_GOSSIP); return 0; } @@ -833,30 +782,12 @@ namespace LuaGlobalFunctions * * @param uint32 menu_id : [GameObject] entry Id * @param uint32 event : [GameObject] gossip event Id, refer to GossipEvents above - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" * @param function function : function to register + * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" */ int RegisterGameObjectGossipEvent(Eluna* E, lua_State* L) { - uint32 entry = Eluna::CHECKVAL(L, 1); - uint32 ev = Eluna::CHECKVAL(L, 2); - uint32 shots; - - if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility. - { - shots = 0; - lua_pushvalue(L, 3); - } - else // Otherwise, shots is the third argument and the function must be the fourth. - { - shots = Eluna::CHECKVAL(L, 3); - luaL_checktype(L, 4, LUA_TFUNCTION); - lua_pushvalue(L, 4); - } - - int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); - if (functionRef > 0) - E->Register(HookMgr::REGTYPE_GAMEOBJECT_GOSSIP, entry, ev, functionRef, shots); + RegisterEntryHelper(E, L, HookMgr::REGTYPE_GAMEOBJECT_GOSSIP); return 0; } @@ -877,30 +808,12 @@ namespace LuaGlobalFunctions * * @param uint32 entry : [Item] entry Id * @param uint32 event : [Item] event Id, refer to ItemEvents above - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" * @param function function : function to register + * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" */ int RegisterItemEvent(Eluna* E, lua_State* L) { - uint32 entry = Eluna::CHECKVAL(L, 1); - uint32 ev = Eluna::CHECKVAL(L, 2); - uint32 shots; - - if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility. - { - shots = 0; - lua_pushvalue(L, 3); - } - else // Otherwise, shots is the third argument and the function must be the fourth. - { - shots = Eluna::CHECKVAL(L, 3); - luaL_checktype(L, 4, LUA_TFUNCTION); - lua_pushvalue(L, 4); - } - - int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); - if (functionRef > 0) - E->Register(HookMgr::REGTYPE_ITEM, entry, ev, functionRef, shots); + RegisterEntryHelper(E, L, HookMgr::REGTYPE_ITEM); return 0; } @@ -918,30 +831,12 @@ namespace LuaGlobalFunctions * * @param uint32 entry : [Item] entry Id * @param uint32 event : [Item] gossip event Id, refer to GossipEvents above - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" * @param function function : function to register + * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" */ int RegisterItemGossipEvent(Eluna* E, lua_State* L) { - uint32 entry = Eluna::CHECKVAL(L, 1); - uint32 ev = Eluna::CHECKVAL(L, 2); - uint32 shots; - - if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility. - { - shots = 0; - lua_pushvalue(L, 3); - } - else // Otherwise, shots is the third argument and the function must be the fourth. - { - shots = Eluna::CHECKVAL(L, 3); - luaL_checktype(L, 4, LUA_TFUNCTION); - lua_pushvalue(L, 4); - } - - int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); - if (functionRef > 0) - E->Register(HookMgr::REGTYPE_ITEM_GOSSIP, entry, ev, functionRef, shots); + RegisterEntryHelper(E, L, HookMgr::REGTYPE_ITEM_GOSSIP); return 0; } @@ -959,30 +854,12 @@ namespace LuaGlobalFunctions * * @param uint32 menu_id : [Player] gossip menu Id * @param uint32 event : [Player] gossip event Id, refer to GossipEvents above - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" * @param function function : function to register + * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" */ int RegisterPlayerGossipEvent(Eluna* E, lua_State* L) { - uint32 menu_id = Eluna::CHECKVAL(L, 1); - uint32 ev = Eluna::CHECKVAL(L, 2); - uint32 shots; - - if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility. - { - shots = 0; - lua_pushvalue(L, 3); - } - else // Otherwise, shots is the third argument and the function must be the fourth. - { - shots = Eluna::CHECKVAL(L, 3); - luaL_checktype(L, 4, LUA_TFUNCTION); - lua_pushvalue(L, 4); - } - - int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); - if (functionRef > 0) - E->Register(HookMgr::REGTYPE_PLAYER_GOSSIP, menu_id, ev, functionRef, shots); + RegisterEntryHelper(E, L, HookMgr::REGTYPE_PLAYER_GOSSIP); return 0; } @@ -1035,30 +912,12 @@ namespace LuaGlobalFunctions * * @param uint32 entry : [Creature] entry Id * @param uint32 event : [Creature] event Id, refer to CreatureEvents above - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" * @param function function : function to register + * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" */ int RegisterCreatureEvent(Eluna* E, lua_State* L) { - uint32 entry = Eluna::CHECKVAL(L, 1); - uint32 ev = Eluna::CHECKVAL(L, 2); - uint32 shots; - - if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility. - { - shots = 0; - lua_pushvalue(L, 3); - } - else // Otherwise, shots is the third argument and the function must be the fourth. - { - shots = Eluna::CHECKVAL(L, 3); - luaL_checktype(L, 4, LUA_TFUNCTION); - lua_pushvalue(L, 4); - } - - int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); - if (functionRef > 0) - E->Register(HookMgr::REGTYPE_CREATURE, entry, ev, functionRef, shots); + RegisterEntryHelper(E, L, HookMgr::REGTYPE_CREATURE); return 0; } @@ -1087,71 +946,12 @@ namespace LuaGlobalFunctions * * @param uint32 entry : [GameObject] entry Id * @param uint32 event : [GameObject] event Id, refer to GameObjectEvents above - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" * @param function function : function to register + * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" */ int RegisterGameObjectEvent(Eluna* E, lua_State* L) { - uint32 entry = Eluna::CHECKVAL(L, 1); - uint32 ev = Eluna::CHECKVAL(L, 2); - uint32 shots; - - if (lua_isfunction(L, 3)) // If the third argument is a function, set shots to 0 for backwards-compatibility. - { - shots = 0; - lua_pushvalue(L, 3); - } - else // Otherwise, shots is the third argument and the function must be the fourth. - { - shots = Eluna::CHECKVAL(L, 3); - luaL_checktype(L, 4, LUA_TFUNCTION); - lua_pushvalue(L, 4); - } - - int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); - if (functionRef > 0) - E->Register(HookMgr::REGTYPE_GAMEOBJECT, entry, ev, functionRef, shots); - return 0; - } - - /** - * Registers a [Battleground] event - * - *
-     * enum BGEvents
-     * {
-     *     BG_EVENT_ON_START                               = 1,    // (event, bg, bgId, instanceId) - Needs to be added to TC
-     *     BG_EVENT_ON_END                                 = 2,    // (event, bg, bgId, instanceId, winner) - Needs to be added to TC
-     *     BG_EVENT_ON_CREATE                              = 3,    // (event, bg, bgId, instanceId) - Needs to be added to TC
-     *     BG_EVENT_ON_PRE_DESTROY                         = 4,    // (event, bg, bgId, instanceId) - Needs to be added to TC
-     *     BG_EVENT_COUNT
-     * };
-     * 
- * - * @param uint32 event : [Battleground] event Id, refer to BGEvents above - * @param uint32 shots = 0 : the number of times the function will be called, 0 means "always call this function" - * @param function function : function to register - */ - int RegisterBGEvent(Eluna* E, lua_State* L) - { - uint32 ev = Eluna::CHECKVAL(L, 1); - uint32 shots; - - if (lua_isfunction(L, 2)) // If the second argument is a function, set shots to 0 for backwards-compatibility. - { - shots = 0; - lua_pushvalue(L, 2); - } - else // Otherwise, shots is the second argument and the function must be the third. - { - shots = Eluna::CHECKVAL(L, 2); - luaL_checktype(L, 3, LUA_TFUNCTION); - lua_pushvalue(L, 3); - } - - int functionRef = luaL_ref(L, LUA_REGISTRYINDEX); - if (functionRef > 0) - E->Register(HookMgr::REGTYPE_BG, 0, ev, functionRef, shots); + RegisterEntryHelper(E, L, HookMgr::REGTYPE_GAMEOBJECT); return 0; } diff --git a/HookMgr.cpp b/HookMgr.cpp index 50772d7..c54554f 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -51,17 +51,7 @@ using namespace HookMgr; const char* _LuaBindType = this->BINDMAP->groupName; \ uint32 _LuaEvent = EVENT; \ int _LuaStackTop = lua_gettop(L); \ - bool _LuaTemporariesDied = false; \ - for (size_t i = 0; i < this->BINDMAP->Bindings[_LuaEvent].size(); ++i) \ - { \ - if (this->BINDMAP->Bindings[_LuaEvent][i].isTemporary) \ - { \ - this->BINDMAP->Bindings[_LuaEvent][i].remainingShots--; \ - if (this->BINDMAP->Bindings[_LuaEvent][i].remainingShots == 0) \ - _LuaTemporariesDied = true; \ - } \ - lua_rawgeti(L, LUA_REGISTRYINDEX, (this->BINDMAP->Bindings[_LuaEvent][i].functionReference)); \ - } \ + this->BINDMAP->PushFuncRefs(L, _LuaEvent); \ int _LuaFuncTop = lua_gettop(L); \ int _LuaFuncCount = _LuaFuncTop-_LuaStackTop; \ Eluna::Push(L, _LuaEvent); @@ -95,17 +85,7 @@ using namespace HookMgr; const char* _LuaBindType = _LuaBind->groupName; \ uint32 _LuaEvent = EVENT; \ int _LuaStackTop = lua_gettop(L); \ - bool _LuaTemporariesDied = false; \ - for (size_t i = 0; i < this->BINDMAP->Bindings[ENTRY][_LuaEvent].size(); ++i) \ - { \ - if (this->BINDMAP->Bindings[ENTRY][_LuaEvent][i].isTemporary) \ - { \ - this->BINDMAP->Bindings[ENTRY][_LuaEvent][i].remainingShots--; \ - if (this->BINDMAP->Bindings[ENTRY][_LuaEvent][i].remainingShots == 0) \ - _LuaTemporariesDied = true; \ - } \ - lua_rawgeti(L, LUA_REGISTRYINDEX, (this->BINDMAP->Bindings[ENTRY][_LuaEvent][i].functionReference)); \ - } \ + this->BINDMAP->PushFuncRefs(L, _LuaEvent, ENTRY); \ int _LuaFuncTop = lua_gettop(L); \ int _LuaFuncCount = _LuaFuncTop-_LuaStackTop; \ Eluna::Push(L, _LuaEvent); @@ -141,8 +121,6 @@ using namespace HookMgr; ELUNA_LOG_ERROR("[Eluna]: Ending event %u for %s, stack top was %i and was supposed to be between %i and %i. Report to devs", _LuaEvent, _LuaBindType, lua_gettop(L), _LuaStackTop, _LuaStackTop + _LuaFuncCount * _LuaReturnValues); \ } \ lua_settop(L, _LuaStackTop); \ - if (_LuaTemporariesDied) \ - _LuaBind->UpdateTemporaryBindings(); \ if (!this->event_level) \ this->InvalidateObjects(); // Invalidate objects on outermost hook call