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
28#include "dl_io.h"
29
30struct lua_State;
31namespace dl
32{
34class LuaScript
35{
36public:
39
40 struct Env
41 {
42 //std::string _funcUpdate;
43 };
47 void SetPathRoot(std::string_view str) { _pathRoot = std::string{ str }; }
48
49
50 bool DoString(std::string_view str);
51 bool DoFile(std::string_view path_name);
52
53 //bool ExcuteFunction(std::string_view name)
54 //{
55 // luabridge::LuaRef v = luabridge::getGlobal(L, name.data());
56 // luabridge::LuaResult ret = v();
57 // if (ret.hasFailed())
58 // {
59 // log_warn("{}", ret.errorMessage());
60 // return false;
61 // }
62 // // todo ret
63 // return true;
64 //}
65 //template <typename T, typename ...Args>
66 //bool ExcuteFunction(std::string_view name, Args&&... args)
67 //{
68 // luabridge::LuaRef v = luabridge::getGlobal(L, name.data());
69 // luabridge::LuaResult ret = v(args...);
70 // if (ret.hasFailed())
71 // {
72 // log_warn("{}", ret.errorMessage());
73 // return false;
74 // }
75 // // todo ret
76 // return true;
77 //}
78
79 bool ExcuteFunction(luabridge::LuaRef func);
80
81 Env& GetEnv() { return _env; }
82 lua_State* GetL() { return L; }
83
84 // 由引擎调用
86private:
87 lua_State* L;
88 Env _env;
89 std::string _pathRoot;
90};
91
92extern LuaScript* g_lua;
93}
lua脚本语言
bool ExcuteFunction(luabridge::LuaRef func)
bool DoFile(std::string_view path_name)
void SetPathRoot(std::string_view str)
设置加载根路径
void RegisterAll()
bool DoString(std::string_view str)
lua_State * GetL()
io相关
LuaScript * g_lua