From de46b91a524c5f2c8e72b379f2900afe34ccb815 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 11 Nov 2021 10:29:17 +0800 Subject: *misc --- Runtime/Lua/LuaBind/LuaBindState.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'Runtime/Lua/LuaBind/LuaBindState.cpp') 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 #include +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; -- cgit v1.1-26-g67d0