summaryrefslogtreecommitdiff
path: root/Runtime/Lua/LuaHelper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Lua/LuaHelper.cpp')
-rw-r--r--Runtime/Lua/LuaHelper.cpp28
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