Eluna add event group type name to the error messages

This commit is contained in:
Rochet2
2014-06-17 21:47:39 +03:00
committed by Foereaper
parent 79fd1d5bab
commit 0fd1615887
3 changed files with 44 additions and 33 deletions

View File

@@ -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);

View File

@@ -58,20 +58,20 @@ L(luaL_newstate()),
m_EventMgr(new EventMgr(*this)),
ServerEventBindings(new EventBind<HookMgr::ServerEvents>(*this)),
PlayerEventBindings(new EventBind<HookMgr::PlayerEvents>(*this)),
GuildEventBindings(new EventBind<HookMgr::GuildEvents>(*this)),
GroupEventBindings(new EventBind<HookMgr::GroupEvents>(*this)),
VehicleEventBindings(new EventBind<HookMgr::VehicleEvents>(*this)),
ServerEventBindings(new EventBind<HookMgr::ServerEvents>("ServerEvents", *this)),
PlayerEventBindings(new EventBind<HookMgr::PlayerEvents>("PlayerEvents", *this)),
GuildEventBindings(new EventBind<HookMgr::GuildEvents>("GuildEvents", *this)),
GroupEventBindings(new EventBind<HookMgr::GroupEvents>("GroupEvents", *this)),
VehicleEventBindings(new EventBind<HookMgr::VehicleEvents>("VehicleEvents", *this)),
PacketEventBindings(new EntryBind<HookMgr::PacketEvents>(*this)),
CreatureEventBindings(new EntryBind<HookMgr::CreatureEvents>(*this)),
CreatureGossipBindings(new EntryBind<HookMgr::GossipEvents>(*this)),
GameObjectEventBindings(new EntryBind<HookMgr::GameObjectEvents>(*this)),
GameObjectGossipBindings(new EntryBind<HookMgr::GossipEvents>(*this)),
ItemEventBindings(new EntryBind<HookMgr::ItemEvents>(*this)),
ItemGossipBindings(new EntryBind<HookMgr::GossipEvents>(*this)),
playerGossipBindings(new EntryBind<HookMgr::GossipEvents>(*this))
PacketEventBindings(new EntryBind<HookMgr::PacketEvents>("PacketEvents", *this)),
CreatureEventBindings(new EntryBind<HookMgr::CreatureEvents>("CreatureEvents", *this)),
CreatureGossipBindings(new EntryBind<HookMgr::GossipEvents>("GossipEvents (creature)", *this)),
GameObjectEventBindings(new EntryBind<HookMgr::GameObjectEvents>("GameObjectEvents", *this)),
GameObjectGossipBindings(new EntryBind<HookMgr::GossipEvents>("GossipEvents (gameobject)", *this)),
ItemEventBindings(new EntryBind<HookMgr::ItemEvents>("ItemEvents", *this)),
ItemGossipBindings(new EntryBind<HookMgr::GossipEvents>("GossipEvents (item)", *this)),
playerGossipBindings(new EntryBind<HookMgr::GossipEvents>("GossipEvents (player)", *this))
{
// open base lua
luaL_openlibs(L);

View File

@@ -686,25 +686,36 @@ template<> Corpse* Eluna::CHECKOBJ<Corpse>(lua_State* L, int narg, bool error);
// #define ELUNA_GUARD() ACE_Guard< ACE_Recursive_Thread_Mutex > ELUNA_GUARD_OBJECT(sEluna->lock);
template<typename T>
struct EventBind
struct ElunaBind
{
typedef std::vector<int> ElunaBindingMap;
typedef std::map<int, ElunaBindingMap> 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<typename T>
struct EventBind : ElunaBind
{
typedef std::vector<int> ElunaBindingMap;
typedef std::map<int, ElunaBindingMap> 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<typename T>
struct EntryBind
struct EntryBind : ElunaBind
{
typedef std::map<int, int> ElunaBindingMap;
typedef UNORDERED_MAP<uint32, ElunaBindingMap> 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)
{