Files
dl_old/dl/script/dl_lua.h
T
2026-04-05 16:12:20 +08:00

64 lines
999 B
C++

/**
* @file dl_lua.h
* @brief lua封装
*
*
* @version 1.0
* @author lveyou
* @date 24-12-23
*
* @note 例如 res/script/、as、mod
* 在 res/script/ui/main.as的脚本,模块名为 mod:ui/main
*
* 直接暴露lua与luabridge
*/
#pragma once
#include <string>
#include <unordered_map>
#define SOL_ALL_SAFETIES_ON 1
#define SOL_PRINT_ERRORS 0
#include <sol/sol.hpp>
#include "dl_io.h"
struct lua_State;
namespace dl
{
//! lua脚本语言
class LuaScript
{
public:
LuaScript();
~LuaScript();
struct Env
{
//std::string _funcUpdate;
};
/**
* @brief 设置加载根路径
*/
void SetPathRoot(std::string_view str) { _pathRoot = std::string{ str }; }
bool DoString(std::string_view str);
bool DoFile(std::string_view path_name);
bool ExcuteFunction(sol::function func);
Env& GetEnv() { return _env; }
sol::state& GetL() { return _l; }
// 由引擎调用
void RegisterAll();
private:
Env _env;
std::string _pathRoot;
sol::state _l;
};
extern LuaScript* g_lua;
}