diff options
author | chai <chaifix@163.com> | 2021-11-11 10:29:17 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-11 10:29:17 +0800 |
commit | de46b91a524c5f2c8e72b379f2900afe34ccb815 (patch) | |
tree | 365122dc27fd1cdcd80939c63ea248e90716c641 /Runtime/Lua/LuaHelper.cpp | |
parent | f706f0e17ac2e7893feddc96b496db89f35e94a8 (diff) |
*misc
Diffstat (limited to 'Runtime/Lua/LuaHelper.cpp')
-rw-r--r-- | Runtime/Lua/LuaHelper.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Runtime/Lua/LuaHelper.cpp b/Runtime/Lua/LuaHelper.cpp index 71fe782..084d4f6 100644 --- a/Runtime/Lua/LuaHelper.cpp +++ b/Runtime/Lua/LuaHelper.cpp @@ -236,4 +236,32 @@ bool LuaHelper::GetLuaClass(LuaBind::State& state, const char* fullName) lua_replace(state, top + 1); lua_settop(state, top + 1); return true; +} + +bool LuaHelper::GetGlobalField(LuaBind::State& state, const char* fullName) +{
+ if (fullName == NULL || strlen(fullName) == 0)
+ return false;
+ int top = state.GetTop();
+ lua_pushvalue(state, LUA_GLOBALSINDEX); + string name = fullName; + while (name.size() > 0) + { + int dot = name.find('.'); + dot = dot != string::npos ? dot : name.size(); + string pkg = name.substr(0, dot); + if (dot < name.size()) + name = name.substr(dot + 1, name.size() - dot - 1); + else + name = ""; + lua_getfield(state, -1, pkg.c_str()); + if (lua_isnil(state, -1)) + { + lua_settop(state, top); + return false; + } + } + lua_replace(state, top + 1); + lua_settop(state, top + 1); + return true; }
\ No newline at end of file |