2026-03-20 11:12:07 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
`chore(lua): refactor addon Lua engine API + progress docs`
- Refactor Lua addon integration:
- Update CMakeLists.txt for addon build paths
- Enhance addons API headers and Lua engine interface
- Add new Lua API addon modules (`lua_api_helpers`, `lua_api_registrations`, `lua_services`, `lua_action_api`, `lua_inventory_api`, `lua_quest_api`, `lua_social_api`, `lua_spell_api`, `lua_system_api`, `lua_unit_api`)
- Update implementation in addon_manager.cpp, lua_engine.cpp, application.cpp, game_handler.cpp
2026-04-03 07:31:06 +03:00
|
|
|
#include "addons/lua_services.hpp"
|
2026-03-21 06:00:06 -07:00
|
|
|
#include <functional>
|
2026-03-20 11:12:07 -07:00
|
|
|
#include <string>
|
2026-03-20 11:23:38 -07:00
|
|
|
#include <vector>
|
2026-03-20 11:12:07 -07:00
|
|
|
|
|
|
|
|
struct lua_State;
|
|
|
|
|
|
|
|
|
|
namespace wowee::game { class GameHandler; }
|
|
|
|
|
|
|
|
|
|
namespace wowee::addons {
|
|
|
|
|
|
2026-03-20 13:07:45 -07:00
|
|
|
struct TocFile; // forward declaration
|
|
|
|
|
|
2026-03-20 11:12:07 -07:00
|
|
|
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);
|
`chore(lua): refactor addon Lua engine API + progress docs`
- Refactor Lua addon integration:
- Update CMakeLists.txt for addon build paths
- Enhance addons API headers and Lua engine interface
- Add new Lua API addon modules (`lua_api_helpers`, `lua_api_registrations`, `lua_services`, `lua_action_api`, `lua_inventory_api`, `lua_quest_api`, `lua_social_api`, `lua_spell_api`, `lua_system_api`, `lua_unit_api`)
- Update implementation in addon_manager.cpp, lua_engine.cpp, application.cpp, game_handler.cpp
2026-04-03 07:31:06 +03:00
|
|
|
void setLuaServices(const LuaServices& services);
|
2026-03-20 11:12:07 -07:00
|
|
|
|
2026-03-20 11:23:38 -07:00
|
|
|
// Fire a WoW event to all registered Lua handlers.
|
|
|
|
|
void fireEvent(const std::string& eventName,
|
|
|
|
|
const std::vector<std::string>& args = {});
|
|
|
|
|
|
2026-03-20 11:40:58 -07:00
|
|
|
// Try to dispatch a slash command via SlashCmdList. Returns true if handled.
|
|
|
|
|
bool dispatchSlashCommand(const std::string& command, const std::string& args);
|
|
|
|
|
|
2026-03-20 12:07:22 -07:00
|
|
|
// Call OnUpdate scripts on all frames that have one.
|
|
|
|
|
void dispatchOnUpdate(float elapsed);
|
|
|
|
|
|
2026-03-20 12:22:50 -07:00
|
|
|
// SavedVariables: load globals from file, save globals to file
|
|
|
|
|
bool loadSavedVariables(const std::string& path);
|
|
|
|
|
bool saveSavedVariables(const std::string& path, const std::vector<std::string>& varNames);
|
|
|
|
|
|
2026-03-20 13:07:45 -07:00
|
|
|
// Store addon info in registry for GetAddOnInfo/GetNumAddOns
|
|
|
|
|
void setAddonList(const std::vector<TocFile>& addons);
|
|
|
|
|
|
2026-03-20 11:12:07 -07:00
|
|
|
lua_State* getState() { return L_; }
|
|
|
|
|
bool isInitialized() const { return L_ != nullptr; }
|
|
|
|
|
|
2026-03-21 06:00:06 -07:00
|
|
|
// 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); }
|
|
|
|
|
|
2026-03-20 11:12:07 -07:00
|
|
|
private:
|
|
|
|
|
lua_State* L_ = nullptr;
|
|
|
|
|
game::GameHandler* gameHandler_ = nullptr;
|
`chore(lua): refactor addon Lua engine API + progress docs`
- Refactor Lua addon integration:
- Update CMakeLists.txt for addon build paths
- Enhance addons API headers and Lua engine interface
- Add new Lua API addon modules (`lua_api_helpers`, `lua_api_registrations`, `lua_services`, `lua_action_api`, `lua_inventory_api`, `lua_quest_api`, `lua_social_api`, `lua_spell_api`, `lua_system_api`, `lua_unit_api`)
- Update implementation in addon_manager.cpp, lua_engine.cpp, application.cpp, game_handler.cpp
2026-04-03 07:31:06 +03:00
|
|
|
LuaServices luaServices_;
|
2026-03-21 06:00:06 -07:00
|
|
|
LuaErrorCallback luaErrorCallback_;
|
2026-03-20 11:12:07 -07:00
|
|
|
|
|
|
|
|
void registerCoreAPI();
|
2026-03-20 11:23:38 -07:00
|
|
|
void registerEventAPI();
|
2026-03-20 11:12:07 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace wowee::addons
|