mirror of
https://github.com/opentibiabr/remeres-map-editor
synced 2026-08-15 18:26:04 -04:00
New Features: • Lua scripting support: embed and run user scripts. • Automatic discovery and execution of scripts from a designated scripts directory. • Included a sample "Hello World" script. Improvements: • Sandboxed execution and safety restrictions for scripts. • Graceful initialization with error logging if scripting fails, and clean shutdown on exit. • Build/system integration updated to ensure Lua and Sol2 are available.
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
//////////////////////////////////////////////////////////////////////
|
|
// This file is part of Remere's Map Editor
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#ifndef RME_LUA_SCRIPT_MANAGER_H
|
|
#define RME_LUA_SCRIPT_MANAGER_H
|
|
|
|
#include "lua_engine.h"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class LuaScriptManager {
|
|
public:
|
|
static LuaScriptManager &getInstance() {
|
|
static LuaScriptManager instance;
|
|
return instance;
|
|
}
|
|
|
|
bool initialize();
|
|
void shutdown();
|
|
bool isInitialized() const {
|
|
return initialized;
|
|
}
|
|
|
|
LuaEngine &getEngine() {
|
|
return engine;
|
|
}
|
|
std::string getLastError() const {
|
|
return lastError;
|
|
}
|
|
|
|
private:
|
|
LuaScriptManager() = default;
|
|
~LuaScriptManager() = default;
|
|
LuaScriptManager(const LuaScriptManager &) = delete;
|
|
LuaScriptManager &operator=(const LuaScriptManager &) = delete;
|
|
|
|
LuaEngine engine;
|
|
std::string lastError;
|
|
bool initialized = false;
|
|
std::vector<std::string> scripts;
|
|
|
|
std::string getScriptsDirectory() const;
|
|
void discoverScripts();
|
|
void scanDirectory(const std::string &directory);
|
|
void runAutoScripts();
|
|
bool executeScript(const std::string &filepath);
|
|
};
|
|
|
|
inline LuaScriptManager &getLuaManager() {
|
|
return LuaScriptManager::getInstance();
|
|
}
|
|
#define g_luaScripts (getLuaManager())
|
|
|
|
#endif // RME_LUA_SCRIPT_MANAGER_H
|