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.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/Runtime/Lua/LuaHelper.cpp b/Runtime/Lua/LuaHelper.cpp
index e458e28..2044ba2 100644
--- a/Runtime/Lua/LuaHelper.cpp
+++ b/Runtime/Lua/LuaHelper.cpp
@@ -25,4 +25,38 @@ Vector2 State::GetValue < Vector2 >(int idx, const Vector2 value)
int LuaHelper::Call(const char* func, const char* params, ...)
{
return 1;
+}
+
+void LuaHelper::OnRegisterNativeClass(LuaBind::State& state, int cls, std::string clsName, std::string pkgName)
+{
+ // 填充类型的元数据
+ lua_newtable(state);
+ int typeIdx = state.GetTop();
+ state.Push("native");
+ state.SetField(typeIdx, "mode");
+ state.Push(clsName);
+ state.SetField(typeIdx, "name");
+ state.Push(pkgName);
+ state.SetField(typeIdx, "package");
+ state.Push(pkgName + '.' + clsName);
+ state.SetField(typeIdx, "fullName");
+ lua_setfield(state, cls, "_type");
+}
+
+bool LuaHelper::IsType(LuaBind::State& state, const char* typeName, int idx)
+{
+ int top = state.GetTop();
+ cc8* type = luaL_typename(state, idx);
+ if (strcmp(type, typeName) == 0)
+ return true;
+ state.GetField(idx, "_type");
+ if (!state.IsTable(-1))
+ {
+ state.Pop(1);
+ return false;
+ }
+ std::string tname = state.GetField(-1, "fullName", "");
+ bool bIsType = tname == typeName;
+ state.SetTop(top);
+ return bIsType;
} \ No newline at end of file