mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-22 23:30:14 +00:00
Implement the WoW-compatible event system that lets addons react to gameplay events in real-time: - RegisterEvent(eventName, handler) — register a Lua function for an event - UnregisterEvent(eventName, handler) — remove a handler - fireEvent() dispatches events to all registered handlers with args Currently fired events: - PLAYER_ENTERING_WORLD — after addons load and world entry completes - PLAYER_LEAVING_WORLD — before logout/disconnect Events are stored in a __WoweeEvents Lua table, dispatched via LuaEngine::fireEvent() which is called from AddonManager::fireEvent(). Error handling logs Lua errors without crashing. Updated HelloWorld addon to use RegisterEvent for world entry/exit.
44 lines
997 B
C++
44 lines
997 B
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
struct lua_State;
|
|
|
|
namespace wowee::game { class GameHandler; }
|
|
|
|
namespace wowee::addons {
|
|
|
|
class LuaEngine {
|
|
public:
|
|
LuaEngine();
|
|
~LuaEngine();
|
|
|
|
LuaEngine(const LuaEngine&) = delete;
|
|
LuaEngine& operator=(const LuaEngine&) = delete;
|
|
|
|
bool initialize();
|
|
void shutdown();
|
|
|
|
bool executeFile(const std::string& path);
|
|
bool executeString(const std::string& code);
|
|
|
|
void setGameHandler(game::GameHandler* handler);
|
|
|
|
// Fire a WoW event to all registered Lua handlers.
|
|
// Extra string args are pushed as event arguments.
|
|
void fireEvent(const std::string& eventName,
|
|
const std::vector<std::string>& args = {});
|
|
|
|
lua_State* getState() { return L_; }
|
|
bool isInitialized() const { return L_ != nullptr; }
|
|
|
|
private:
|
|
lua_State* L_ = nullptr;
|
|
game::GameHandler* gameHandler_ = nullptr;
|
|
|
|
void registerCoreAPI();
|
|
void registerEventAPI();
|
|
};
|
|
|
|
} // namespace wowee::addons
|