dl
dl
script
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
26
struct
lua_State;
27
namespace
dl
28
{
30
class
LuaScript
31
{
32
public
:
33
LuaScript
();
34
~LuaScript
();
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; }
76
private
:
77
lua_State*
L
;
78
Env _env;
79
std::string _pathRoot;
80
};
81
82
extern
LuaScript*
g_lua
;
83
}
dl::LuaScript::LuaScript
LuaScript()
dl::LuaScript::GetEnv
Env & GetEnv()
定义
dl_lua.h:74
dl::LuaScript::DoFile
bool DoFile(std::string_view path_name)
dl::LuaScript::SetPathRoot
void SetPathRoot(std::string_view str)
设置加载根路径
定义
dl_lua.h:43
dl::LuaScript::ExcuteFunction
bool ExcuteFunction(std::string_view name, Args &&... args)
定义
dl_lua.h:61
dl::LuaScript::ExcuteFunction
bool ExcuteFunction(std::string_view name)
定义
dl_lua.h:48
dl::LuaScript::~LuaScript
~LuaScript()
dl::LuaScript::GetL
lua_State * GetL()
定义
dl_lua.h:75
dl_io.h
io相关
log_warn
#define log_warn(...)
定义
dl_log.h:230
dl
定义
dl_array2.h:19
dl::KeyCode::T
@ T
定义
dl_input.h:122
dl::KeyCode::L
@ L
定义
dl_input.h:114
dl::g_lua
LuaScript * g_lua
dl::LuaScript::Env
定义
dl_lua.h:37
制作者
1.13.1