summaryrefslogtreecommitdiff
path: root/Runtime/Lua/LuaBind/LuaBindState.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Lua/LuaBind/LuaBindState.cpp')
-rw-r--r--Runtime/Lua/LuaBind/LuaBindState.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/Runtime/Lua/LuaBind/LuaBindState.cpp b/Runtime/Lua/LuaBind/LuaBindState.cpp
index 92e46cd..3fefa52 100644
--- a/Runtime/Lua/LuaBind/LuaBindState.cpp
+++ b/Runtime/Lua/LuaBind/LuaBindState.cpp
@@ -7,6 +7,8 @@
#include <string.h>
#include <string>
+using namespace std;
+
namespace LuaBind
{
OnRegisterClassHandler onRegisterNativeClass = NULL;
@@ -415,6 +417,34 @@ namespace LuaBind
lua_gettable(mState, idx);
}
+ bool State::GetGlobalField(const char* fullName)
+ {
+ if (fullName == NULL || strlen(fullName) == 0)
+ return false;
+ int top = GetTop();
+ lua_pushvalue(*this, 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(*this, -1, pkg.c_str());
+ if (lua_isnil(*this, -1))
+ {
+ lua_settop(*this, top);
+ return false;
+ }
+ }
+ lua_replace(*this, top + 1);
+ lua_settop(*this, top + 1);
+ return true;
+ }
+
std::string State::GetField(int idx, cc8* key, cc8* default_value)
{
std::string str;