From 0fd161588711c25b6a3789537986e13c7df7e4ca Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Tue, 17 Jun 2014 21:47:39 +0300 Subject: [PATCH] Eluna add event group type name to the error messages --- HookMgr.cpp | 10 ++++++++-- LuaEngine.cpp | 26 +++++++++++++------------- LuaEngine.h | 41 +++++++++++++++++++++++------------------ 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/HookMgr.cpp b/HookMgr.cpp index 6c14ac8..54c4352 100644 --- a/HookMgr.cpp +++ b/HookMgr.cpp @@ -30,6 +30,7 @@ ENDCALL(); if (!BINDMAP->HasEvents(EVENT)) \ RET; \ lua_State* L = sEluna->L; \ + const char* _LuaBindType = sEluna->BINDMAP->groupName; \ uint32 _LuaEvent = EVENT; \ int _LuaStackTop = lua_gettop(L); \ for (size_t i = 0; i < sEluna->BINDMAP->Bindings[_LuaEvent].size(); ++i) \ @@ -44,7 +45,7 @@ ENDCALL(); int _LuaParams = lua_gettop(L) - _LuaFuncTop; \ if (_LuaParams < 1) \ { \ - ELUNA_LOG_ERROR("[Eluna]: Executing event %u, params was %i. Report to devs", _LuaEvent, _LuaParams); \ + ELUNA_LOG_ERROR("[Eluna]: Executing event %u for %s, params was %i. Report to devs", _LuaEvent, _LuaBindType, _LuaParams); \ } \ for (int j = _LuaFuncTop-_LuaStackTop; j > 0; --j) \ { \ @@ -63,6 +64,7 @@ ENDCALL(); if (!_Luabind) \ RET; \ lua_State* L = sEluna->L; \ + const char* _LuaBindType = sEluna->BINDMAP->groupName; \ uint32 _LuaEvent = EVENT; \ int _LuaStackTop = lua_gettop(L); \ lua_rawgeti(L, LUA_REGISTRYINDEX, _Luabind); \ @@ -79,7 +81,11 @@ ENDCALL(); #define ENDCALL() \ if (_LuaReturnValues != LUA_MULTRET && lua_gettop(L) != _LuaStackTop + _LuaReturnValues) \ { \ - ELUNA_LOG_ERROR("[Eluna]: Ending event %u, stack top was %i and was supposed to be %i. Report to devs", _LuaEvent, lua_gettop(L), _LuaStackTop + _LuaReturnValues); \ + ELUNA_LOG_ERROR("[Eluna]: Ending event %u for %s, stack top was %i and was supposed to be %i. Report to devs", _LuaEvent, _LuaBindType, lua_gettop(L), _LuaStackTop + _LuaReturnValues); \ + } \ + else if (_LuaReturnValues == LUA_MULTRET && lua_gettop(L) < _LuaStackTop) \ + { \ + ELUNA_LOG_ERROR("[Eluna]: Ending event %u for %s, stack top was %i and was supposed to be >= %i. Report to devs", _LuaEvent, _LuaBindType, lua_gettop(L), _LuaStackTop); \ } \ lua_settop(L, _LuaStackTop); diff --git a/LuaEngine.cpp b/LuaEngine.cpp index 8752bec..078a196 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -58,20 +58,20 @@ L(luaL_newstate()), m_EventMgr(new EventMgr(*this)), -ServerEventBindings(new EventBind(*this)), -PlayerEventBindings(new EventBind(*this)), -GuildEventBindings(new EventBind(*this)), -GroupEventBindings(new EventBind(*this)), -VehicleEventBindings(new EventBind(*this)), +ServerEventBindings(new EventBind("ServerEvents", *this)), +PlayerEventBindings(new EventBind("PlayerEvents", *this)), +GuildEventBindings(new EventBind("GuildEvents", *this)), +GroupEventBindings(new EventBind("GroupEvents", *this)), +VehicleEventBindings(new EventBind("VehicleEvents", *this)), -PacketEventBindings(new EntryBind(*this)), -CreatureEventBindings(new EntryBind(*this)), -CreatureGossipBindings(new EntryBind(*this)), -GameObjectEventBindings(new EntryBind(*this)), -GameObjectGossipBindings(new EntryBind(*this)), -ItemEventBindings(new EntryBind(*this)), -ItemGossipBindings(new EntryBind(*this)), -playerGossipBindings(new EntryBind(*this)) +PacketEventBindings(new EntryBind("PacketEvents", *this)), +CreatureEventBindings(new EntryBind("CreatureEvents", *this)), +CreatureGossipBindings(new EntryBind("GossipEvents (creature)", *this)), +GameObjectEventBindings(new EntryBind("GameObjectEvents", *this)), +GameObjectGossipBindings(new EntryBind("GossipEvents (gameobject)", *this)), +ItemEventBindings(new EntryBind("ItemEvents", *this)), +ItemGossipBindings(new EntryBind("GossipEvents (item)", *this)), +playerGossipBindings(new EntryBind("GossipEvents (player)", *this)) { // open base lua luaL_openlibs(L); diff --git a/LuaEngine.h b/LuaEngine.h index defe369..69488cd 100644 --- a/LuaEngine.h +++ b/LuaEngine.h @@ -686,25 +686,36 @@ template<> Corpse* Eluna::CHECKOBJ(lua_State* L, int narg, bool error); // #define ELUNA_GUARD() ACE_Guard< ACE_Recursive_Thread_Mutex > ELUNA_GUARD_OBJECT(sEluna->lock); -template -struct EventBind +struct ElunaBind { - typedef std::vector ElunaBindingMap; - typedef std::map ElunaEntryMap; - Eluna& E; + const char* groupName; - EventBind(Eluna& _E): E(_E) + ElunaBind(const char* bindGroupName, Eluna& _E): E(_E), groupName(bindGroupName) { } - ~EventBind() + ~ElunaBind() { Clear(); } + // unregisters all registered functions and clears all registered events from the bindings + virtual void Clear() {}; +}; + +template +struct EventBind : ElunaBind +{ + typedef std::vector ElunaBindingMap; + typedef std::map ElunaEntryMap; + + EventBind(const char* bindGroupName, Eluna& _E): ElunaBind(bindGroupName, _E) + { + } + // unregisters all registered functions and clears all registered events from the bind std::maps (reset) - void Clear() + void Clear() override { for (ElunaEntryMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr) { @@ -746,23 +757,17 @@ struct EventBind }; template -struct EntryBind +struct EntryBind : ElunaBind { typedef std::map ElunaBindingMap; typedef UNORDERED_MAP ElunaEntryMap; - Eluna& E; - - EntryBind(Eluna& _E): E(_E) + EntryBind(const char* bindGroupName, Eluna& _E): ElunaBind(bindGroupName, _E) { } - ~EntryBind() - { - Clear(); - } - - void Clear() // unregisters all registered functions and clears all registered events from the bind std::maps (reset) + // unregisters all registered functions and clears all registered events from the bindmap + void Clear() override { for (ElunaEntryMap::iterator itr = Bindings.begin(); itr != Bindings.end(); ++itr) {