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