diff options
author | chai <chaifix@163.com> | 2021-10-25 03:22:49 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-25 03:22:49 +0800 |
commit | 0816cd70ca1a213b6ed872bcf3c0bf0912473722 (patch) | |
tree | ede23a398e78106551434ca762362ca04fd1ba8c /Runtime/Lua | |
parent | 180b715e72ffc292ebbc4695f8a63ce449004d27 (diff) |
*misc
Diffstat (limited to 'Runtime/Lua')
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindState.cpp | 6 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindState.h | 1 | ||||
-rw-r--r-- | Runtime/Lua/LuaHelper.cpp | 34 | ||||
-rw-r--r-- | Runtime/Lua/LuaHelper.h | 4 |
4 files changed, 44 insertions, 1 deletions
diff --git a/Runtime/Lua/LuaBind/LuaBindState.cpp b/Runtime/Lua/LuaBind/LuaBindState.cpp index c9183ff..7c5f043 100644 --- a/Runtime/Lua/LuaBind/LuaBindState.cpp +++ b/Runtime/Lua/LuaBind/LuaBindState.cpp @@ -284,6 +284,12 @@ namespace LuaBind return ((t == LUA_TNONE) || (t == LUA_TNIL)); } + bool State::IsTable(int idx) + { + int check = lua_type(mState, idx); + return check == LUA_TTABLE; + } + bool State::IsTableOrUserdata(int idx) { int check = lua_type(mState, idx); diff --git a/Runtime/Lua/LuaBind/LuaBindState.h b/Runtime/Lua/LuaBind/LuaBindState.h index c81ba8c..e7e2807 100644 --- a/Runtime/Lua/LuaBind/LuaBindState.h +++ b/Runtime/Lua/LuaBind/LuaBindState.h @@ -85,6 +85,7 @@ namespace LuaBind bool IsNil(int idx); bool IsNilOrNone(int idx); + bool IsTable(int idx); bool IsTableOrUserdata(int idx); bool IsTrueOrNotNil(int idx); bool IsType(int idx, int type); 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 diff --git a/Runtime/Lua/LuaHelper.h b/Runtime/Lua/LuaHelper.h index 10d9421..56dae54 100644 --- a/Runtime/Lua/LuaHelper.h +++ b/Runtime/Lua/LuaHelper.h @@ -10,6 +10,8 @@ class LuaHelper public:
static int Call(const char* func, const char* params, ...);
-};
+ static bool IsType(LuaBind::State& state, const char* typeName, int idx);
+ static void OnRegisterNativeClass(LuaBind::State& state, int cls, std::string clsName, std::string pkgName);
+};
\ No newline at end of file |