summaryrefslogtreecommitdiff
path: root/Runtime/Lua/LuaHelper.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-09 19:22:13 +0800
committerchai <chaifix@163.com>2021-11-09 19:22:13 +0800
commitd8417b03b9c2a820d3d3be0dfa80841b4d1f4c04 (patch)
tree7d036d283bd7a626d56c5c5a725733df439c8368 /Runtime/Lua/LuaHelper.cpp
parent13f477664c07826c92eac774f0035994c460c057 (diff)
*misc
Diffstat (limited to 'Runtime/Lua/LuaHelper.cpp')
-rw-r--r--Runtime/Lua/LuaHelper.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/Runtime/Lua/LuaHelper.cpp b/Runtime/Lua/LuaHelper.cpp
index f1dc349..71fe782 100644
--- a/Runtime/Lua/LuaHelper.cpp
+++ b/Runtime/Lua/LuaHelper.cpp
@@ -5,6 +5,7 @@
#include "Runtime/Graphics/Color.h"
using namespace LuaBind;
+using namespace std;
template <>
Rect State::GetValue < Rect >(int idx, const Rect value)
@@ -207,4 +208,32 @@ bool LuaHelper::IsType(LuaBind::State& state, const char* typeName, int idx)
bool LuaHelper::InstantiateClass(LuaBind::State& state, const char* classFullName)
{
return false;
+}
+
+bool LuaHelper::GetLuaClass(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