dl
dl_lua.h
浏览该文件的文档.
1
15#pragma once
16
17#include <string>
18#include <unordered_map>
19
20#define LUA_USE_APICHECK
21//#define LUABRIDGE_HAS_EXCEPTIONS 0
22
23// std::span会转为lua的table,故而无法转回来,所以关闭默认实现
24#define LUABRIDGE_DISABLE_CXX20_SPAN
25#include <lua.hpp>
26#include <LuaBridge/LuaBridge.h>
27
29#include "dl_io.h"
30
31struct lua_State;
32namespace dl
33{
34
35 using luabridge::LuaRef;
36
39{
40public:
43
44 struct Env
45 {
46 //std::string _funcUpdate;
47 };
48
51 void SetPathRoot(std::string_view str) { _pathRoot = std::string{ str }; }
52
56 bool DoString(std::string_view str);
60 bool DoFile(std::string_view path_name);
64 bool DoFileEx(std::string_view path_name, LuaRef& ret);
65
66 //bool ExcuteFunction(std::string_view name)
67 //{
68 // luabridge::LuaRef v = luabridge::getGlobal(L, name.data());
69 // luabridge::LuaResult ret = v();
70 // if (ret.hasFailed())
71 // {
72 // log_warn("{}", ret.errorMessage());
73 // return false;
74 // }
75 // // todo ret
76 // return true;
77 //}
78 //template <typename T, typename ...Args>
79 //bool ExcuteFunction(std::string_view name, Args&&... args)
80 //{
81 // luabridge::LuaRef v = luabridge::getGlobal(L, name.data());
82 // luabridge::LuaResult ret = v(args...);
83 // if (ret.hasFailed())
84 // {
85 // log_warn("{}", ret.errorMessage());
86 // return false;
87 // }
88 // // todo ret
89 // return true;
90 //}
91
97 bool CallFunction(LuaRef func);
98
104 std::string GetRefString(LuaRef ref);
105
106 Env& GetEnv() { return _env; }
107 lua_State* GetL() { return L; }
108
109 // 由引擎调用
111private:
112 lua_State* L;
113 Env _env;
114 std::string _pathRoot;
115};
116
117extern LuaScript* g_lua;
118}
lua脚本语言
bool DoFile(std::string_view path_name)
执行lua文件
void SetPathRoot(std::string_view str)
设置加载根路径
void RegisterAll()
bool DoString(std::string_view str)
执行lua字符串
bool DoFileEx(std::string_view path_name, LuaRef &ret)
执行lua文件,并获取返回值
lua_State * GetL()
bool CallFunction(LuaRef func)
调用函数
std::string GetRefString(LuaRef ref)
返回lua对象字符串
io相关
lua脚本接口注册(标准容器转换)
LuaScript * g_lua