feat: display Lua addon errors as in-game UI errors

Previously Lua addon errors only logged to the log file. Now they
display as red UI error text to the player (same as spell errors and
game warnings), helping addon developers debug issues in real-time.

Add LuaErrorCallback to LuaEngine, fire it from event handler and
frame OnEvent pcall error paths. Wire the callback to GameHandler's
addUIError in application.cpp.
This commit is contained in:
Kelsi 2026-03-21 06:00:06 -07:00
parent 64c0c75bbf
commit 19b8d31da2
3 changed files with 17 additions and 3 deletions

View file

@ -3820,8 +3820,9 @@ void LuaEngine::fireEvent(const std::string& eventName,
int nargs = 1 + static_cast<int>(args.size());
if (lua_pcall(L_, nargs, 0, 0) != 0) {
const char* err = lua_tostring(L_, -1);
LOG_ERROR("LuaEngine: event '", eventName, "' handler error: ",
err ? err : "(unknown)");
std::string errStr = err ? err : "(unknown)";
LOG_ERROR("LuaEngine: event '", eventName, "' handler error: ", errStr);
if (luaErrorCallback_) luaErrorCallback_(errStr);
lua_pop(L_, 1);
}
}
@ -3847,7 +3848,10 @@ void LuaEngine::fireEvent(const std::string& eventName,
for (const auto& arg : args) lua_pushstring(L_, arg.c_str());
int nargs = 2 + static_cast<int>(args.size());
if (lua_pcall(L_, nargs, 0, 0) != 0) {
LOG_ERROR("LuaEngine: frame OnEvent error: ", lua_tostring(L_, -1));
const char* ferr = lua_tostring(L_, -1);
std::string ferrStr = ferr ? ferr : "(unknown)";
LOG_ERROR("LuaEngine: frame OnEvent error: ", ferrStr);
if (luaErrorCallback_) luaErrorCallback_(ferrStr);
lua_pop(L_, 1);
}
} else {