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
#define LUABRIDGE_HAS_EXCEPTIONS 0
22
#include <lua.hpp>
23
#include <LuaBridge/LuaBridge.h>
24
25
#include "
dl_io.h
"
26
27
struct
lua_State;
28
namespace
dl
29
{
31
class
LuaScript
32
{
33
public
:
34
LuaScript
();
35
~LuaScript
();
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; }
77
private
:
78
lua_State*
L
;
79
Env _env;
80
std::string _pathRoot;
81
};
82
83
extern
LuaScript*
g_lua
;
84
}
dl::LuaScript::LuaScript
LuaScript()
dl::LuaScript::GetEnv
Env & GetEnv()
定义
dl_lua.h:75
dl::LuaScript::DoFile
bool DoFile(std::string_view path_name)
dl::LuaScript::SetPathRoot
void SetPathRoot(std::string_view str)
设置加载根路径
定义
dl_lua.h:44
dl::LuaScript::ExcuteFunction
bool ExcuteFunction(std::string_view name, Args &&... args)
定义
dl_lua.h:62
dl::LuaScript::ExcuteFunction
bool ExcuteFunction(std::string_view name)
定义
dl_lua.h:49
dl::LuaScript::~LuaScript
~LuaScript()
dl::LuaScript::GetL
lua_State * GetL()
定义
dl_lua.h:76
dl_io.h
io相关
log_warn
#define log_warn(...)
定义
dl_log.h:230
dl
定义
dl_array.h:21
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:38
制作者
1.13.1