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