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{
31{
32public:
35
36 struct Env
37 {
38 //std::string _funcUpdate;
39 };
40
43 void SetPathRoot(std::string_view str) { _pathRoot = std::string{ str }; }
44
45
46 bool DoFile(std::string_view path_name);
47
48 bool ExcuteFunction(std::string_view name)
49 {
50 luabridge::LuaRef v = luabridge::getGlobal(L, name.data());
51 luabridge::LuaResult ret = v();
52 if (ret.hasFailed())
53 {
54 log_warn("{}", ret.errorMessage());
55 return false;
56 }
57 // todo ret
58 return true;
59 }
60 template <typename T, typename ...Args>
61 bool ExcuteFunction(std::string_view name, Args&&... args)
62 {
63 luabridge::LuaRef v = luabridge::getGlobal(L, name.data());
64 luabridge::LuaResult ret = v(args...);
65 if (ret.hasFailed())
66 {
67 log_warn("{}", ret.errorMessage());
68 return false;
69 }
70 // todo ret
71 return true;
72 }
73
74 Env& GetEnv() { return _env; }
75 lua_State* GetL() { return L; }
76private:
77 lua_State* L;
78 Env _env;
79 std::string _pathRoot;
80};
81
82extern LuaScript* g_lua;
83}
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