dl
dl_lua.h
浏览该文件的文档.
1
15#pragma once
16
17#include <string>
18#include <unordered_map>
19
20#define LUA_USE_APICHECK
21#include <lua.hpp>
22#include <LuaBridge/LuaBridge.h>
23
24#include "dl_io.h"
25
26struct lua_State;
27namespace dl
28{
30{
31public:
34
35 struct Env
36 {
37 //std::string _funcUpdate;
38 };
39
42 void SetPathRoot(std::string_view str) { _pathRoot = std::string{ str }; }
43
44
45 bool DoFile(std::string_view path_name);
46
47 bool ExcuteFunction(std::string_view name)
48 {
49 luabridge::LuaRef v = luabridge::getGlobal(L, name.data());
50 luabridge::LuaResult ret = v();
51 if (ret.hasFailed())
52 {
53 log_warn("{}", ret.errorMessage());
54 return false;
55 }
56 // todo ret
57 return true;
58 }
59 template <typename T, typename ...Args>
60 bool ExcuteFunction(std::string_view name, Args&&... args)
61 {
62 luabridge::LuaRef v = luabridge::getGlobal(L, name.data());
63 luabridge::LuaResult ret = v(args);
64 if (ret.hasFailed())
65 {
66 log_warn("{}", ret.errorMessage());
67 return false;
68 }
69 // todo ret
70 return true;
71 }
72
73 Env& GetEnv() { return _env; }
74 lua_State* GetL() { return L; }
75private:
76 lua_State* L;
77 Env _env;
78 std::string _pathRoot;
79};
80
81extern LuaScript* g_lua;
82}
bool DoFile(std::string_view path_name)
void SetPathRoot(std::string_view str)
设置加载根路径
bool ExcuteFunction(std::string_view name, Args &&... args)
bool ExcuteFunction(std::string_view name)
lua_State * GetL()
io相关
#define log_warn(...)
LuaScript * g_lua