Kelsidavis-WoWee/include/addons/lua_engine.hpp
Kelsi c1820fd07d feat: add WoW utility functions and SlashCmdList for addon slash commands
Utility functions:
- strsplit(delim, str), strtrim(str), wipe(table)
- date(format), time() — safe replacements for removed os.date/os.time
- format (alias for string.format), tinsert/tremove (table aliases)

SlashCmdList system:
- Addons can register custom slash commands via the standard WoW pattern:
  SLASH_MYADDON1 = "/myaddon"
  SlashCmdList["MYADDON"] = function(args) ... end
- Chat input checks SlashCmdList before built-in commands
- dispatchSlashCommand() iterates SLASH_<NAME>1..9 globals to match

Total WoW API surface: 23 functions + SlashCmdList + 14 events.
2026-03-20 11:40:58 -07:00

46 lines
1.1 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);
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