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
{
29
class
LuaScript
30
{
31
public
:
32
LuaScript
();
33
~LuaScript
();
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; }
75
private
:
76
lua_State*
L
;
77
Env _env;
78
std::string _pathRoot;
79
};
80
81
extern
LuaScript*
g_lua
;
82
}
dl::LuaScript::LuaScript
LuaScript()
dl::LuaScript::GetEnv
Env & GetEnv()
定义
dl_lua.h:73
dl::LuaScript::DoFile
bool DoFile(std::string_view path_name)
dl::LuaScript::SetPathRoot
void SetPathRoot(std::string_view str)
设置加载根路径
定义
dl_lua.h:42
dl::LuaScript::ExcuteFunction
bool ExcuteFunction(std::string_view name, Args &&... args)
定义
dl_lua.h:60
dl::LuaScript::ExcuteFunction
bool ExcuteFunction(std::string_view name)
定义
dl_lua.h:47
dl::LuaScript::~LuaScript
~LuaScript()
dl::LuaScript::GetL
lua_State * GetL()
定义
dl_lua.h:74
dl_io.h
io相关
log_warn
#define log_warn(...)
定义
dl_log.h:214
dl
定义
dl_array2.h:18
dl::KeyCode::T
@ T
定义
dl_input.h:120
dl::KeyCode::L
@ L
定义
dl_input.h:112
dl::g_lua
LuaScript * g_lua
dl::LuaScript::Env
定义
dl_lua.h:36
制作者
1.13.1