mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Fix hookmgr rewrite
Fix: - crash on reload - crash on error in call - a warning from type change
This commit is contained in:
@@ -93,7 +93,7 @@ int Eluna::SetupStack(EventBind<T>* event_bindings, EntryBind<T>* entry_bindings
|
||||
ASSERT(number_of_arguments == this->push_counter);
|
||||
// Stack: [arguments]
|
||||
|
||||
Push((int)event_id);
|
||||
Push(event_id);
|
||||
this->push_counter = 0;
|
||||
++number_of_arguments;
|
||||
// Stack: [arguments], event_id
|
||||
@@ -143,7 +143,7 @@ void Eluna::ReplaceArgument(T value, uint8 index, uint8 number_of_arguments, uin
|
||||
int Eluna::CallOneFunction(int number_of_functions, int number_of_arguments, int number_of_results)
|
||||
{
|
||||
++number_of_arguments; // Caller doesn't know about `event_id`.
|
||||
ASSERT(number_of_functions > 0 && number_of_results >= 0);
|
||||
ASSERT(number_of_functions > 0 && number_of_arguments > 0 && number_of_results >= 0);
|
||||
// Stack: event_id, [arguments], [functions]
|
||||
|
||||
int functions_top = lua_gettop(L);
|
||||
@@ -208,6 +208,7 @@ template<typename T>
|
||||
bool Eluna::CallAllFunctionsBool(EventBind<T>* event_bindings, EntryBind<T>* entry_bindings, T event_id, uint32 entry, bool default_value)
|
||||
{
|
||||
bool result = default_value;
|
||||
// Note: number_of_arguments here does not count in eventID, which is pushed in SetupStack
|
||||
int number_of_arguments = this->push_counter;
|
||||
// Stack: [arguments]
|
||||
|
||||
@@ -220,7 +221,7 @@ bool Eluna::CallAllFunctionsBool(EventBind<T>* event_bindings, EntryBind<T>* ent
|
||||
--number_of_functions;
|
||||
// Stack: event_id, [arguments], [functions - 1], result
|
||||
|
||||
if (lua_isboolean(L, r) && (bool)lua_toboolean(L, r) != default_value)
|
||||
if (lua_isboolean(L, r) && (lua_toboolean(L, r) == 1) != default_value)
|
||||
result = !default_value;
|
||||
|
||||
lua_pop(L, 1);
|
||||
@@ -461,13 +462,13 @@ void Eluna::OnShutdownCancel()
|
||||
|
||||
void Eluna::OnWorldUpdate(uint32 diff)
|
||||
{
|
||||
ELUNA_LOCK(this);
|
||||
if (reload)
|
||||
{
|
||||
ReloadEluna();
|
||||
return;
|
||||
}
|
||||
|
||||
ELUNA_LOCK(this);
|
||||
eventMgr->globalProcessor->Update(diff);
|
||||
|
||||
Push(diff);
|
||||
|
||||
@@ -432,19 +432,31 @@ void Eluna::report(lua_State* luastate)
|
||||
void Eluna::ExecuteCall(int params, int res)
|
||||
{
|
||||
int top = lua_gettop(L);
|
||||
int type = lua_type(L, top - params);
|
||||
|
||||
// Expected: function, [parameters]
|
||||
ASSERT(top > params);
|
||||
|
||||
// Check function type
|
||||
int type = lua_type(L, top - params);
|
||||
if (type != LUA_TFUNCTION)
|
||||
{
|
||||
lua_pop(L, params + 1); // Cleanup the stack.
|
||||
ELUNA_LOG_ERROR("[Eluna]: Cannot execute call: registered value is %s, not a function.", lua_typename(L, type));
|
||||
return;
|
||||
ASSERT(false);
|
||||
}
|
||||
|
||||
// Objects are invalidated when event level hits 0
|
||||
++event_level;
|
||||
if (lua_pcall(L, params, res, 0))
|
||||
report(L);
|
||||
int result = lua_pcall(L, params, res, 0);
|
||||
--event_level;
|
||||
|
||||
// lua_pcall returns 0 on success.
|
||||
// On error we report errors and push nils for expected amount of returned values
|
||||
if (result)
|
||||
{
|
||||
report(L);
|
||||
for (int i = 0; i < res; ++i)
|
||||
lua_pushnil(L);
|
||||
}
|
||||
}
|
||||
|
||||
void Eluna::Push(lua_State* luastate)
|
||||
|
||||
@@ -247,12 +247,7 @@ public:
|
||||
void Push(const double value) { Push(L, value); ++push_counter; }
|
||||
void Push(const std::string& value) { Push(L, value); ++push_counter; }
|
||||
void Push(const char* value) { Push(L, value); ++push_counter; }
|
||||
template<typename T> void Push(T const* ptr){ Push<T>(L, ptr); ++push_counter; }
|
||||
void Push(Object const* obj) { Push(L, obj); ++push_counter; }
|
||||
void Push(WorldObject const* obj) { Push(L, obj); ++push_counter; }
|
||||
void Push(Unit const* unit) { Push(L, unit); ++push_counter; }
|
||||
void Push(Pet const* pet) { Push(L, pet); ++push_counter; }
|
||||
void Push(TempSummon const* summon) { Push(L, summon); ++push_counter; }
|
||||
template<typename T> void Push(T const* ptr){ Push(L, ptr); ++push_counter; }
|
||||
|
||||
// Checks
|
||||
template<typename T> static T CHECKVAL(lua_State* luastate, int narg);
|
||||
|
||||
Reference in New Issue
Block a user