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

@ -1,5 +1,6 @@
#pragma once
#include <functional>
#include <string>
#include <vector>
@ -47,9 +48,14 @@ public:
lua_State* getState() { return L_; }
bool isInitialized() const { return L_ != nullptr; }
// Optional callback for Lua errors (displayed as UI errors to the player)
using LuaErrorCallback = std::function<void(const std::string&)>;
void setLuaErrorCallback(LuaErrorCallback cb) { luaErrorCallback_ = std::move(cb); }
private:
lua_State* L_ = nullptr;
game::GameHandler* gameHandler_ = nullptr;
LuaErrorCallback luaErrorCallback_;
void registerCoreAPI();
void registerEventAPI();