/** * @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 #include #define LUA_USE_APICHECK //#define LUABRIDGE_HAS_EXCEPTIONS 0 // std::span会转为lua的table,故而无法转回来,所以关闭默认实现 #define LUABRIDGE_DISABLE_CXX20_SPAN #include #include #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(std::string_view name) //{ // luabridge::LuaRef v = luabridge::getGlobal(L, name.data()); // luabridge::LuaResult ret = v(); // if (ret.hasFailed()) // { // log_warn("{}", ret.errorMessage()); // return false; // } // // todo ret // return true; //} //template //bool ExcuteFunction(std::string_view name, Args&&... args) //{ // luabridge::LuaRef v = luabridge::getGlobal(L, name.data()); // luabridge::LuaResult ret = v(args...); // if (ret.hasFailed()) // { // log_warn("{}", ret.errorMessage()); // return false; // } // // todo ret // return true; //} bool ExcuteFunction(luabridge::LuaRef func); Env& GetEnv() { return _env; } lua_State* GetL() { return L; } // 由引擎调用 void RegisterAll(); private: lua_State* L; Env _env; std::string _pathRoot; }; extern LuaScript* g_lua; }