Kelsidavis-WoWee/include/addons/lua_engine.hpp
Kelsi 1f8660f329 feat: add OnUpdate frame script for per-frame addon callbacks
Frames can now set an OnUpdate script that fires every frame with
the elapsed time as an argument. This enables addon timers, polling,
and animations.

  local f = CreateFrame("Frame")
  f:SetScript("OnUpdate", function(self, elapsed)
      -- called every frame with deltaTime
  end)

OnUpdate only fires for visible frames (frame:Hide() pauses it).
Tracked in __WoweeOnUpdateFrames table, dispatched via
LuaEngine::dispatchOnUpdate() called from the Application main loop.
2026-03-20 12:07:22 -07:00

49 lines
1.2 KiB
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.
void fireEvent(const std::string& eventName,
const std::vector<std::string>& args = {});
// Try to dispatch a slash command via SlashCmdList. Returns true if handled.
bool dispatchSlashCommand(const std::string& command, const std::string& args);
// Call OnUpdate scripts on all frames that have one.
void dispatchOnUpdate(float elapsed);
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