diff options
author | chai <chaifix@163.com> | 2021-11-19 15:33:48 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-19 15:33:48 +0800 |
commit | 1cd31d14c95f9d52e30fbc611df5da4b46f048d9 (patch) | |
tree | 86dbda850f9b8ed26b152c6521adc0a777d6563a /Runtime | |
parent | 2ab7fad7b308debba0aacbf76831569f360d19a0 (diff) |
*misc
Diffstat (limited to 'Runtime')
-rw-r--r-- | Runtime/GUI/UIQuad.cpp | 2 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindInvoker.h | 6 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindLClass.h | 12 | ||||
-rw-r--r-- | Runtime/Lua/LuaBind/LuaBindState.h | 4 | ||||
-rw-r--r-- | Runtime/Math/ITransData.h | 7 | ||||
-rw-r--r-- | Runtime/Math/Vector2.h | 12 |
6 files changed, 40 insertions, 3 deletions
diff --git a/Runtime/GUI/UIQuad.cpp b/Runtime/GUI/UIQuad.cpp index e28a772..c57685c 100644 --- a/Runtime/GUI/UIQuad.cpp +++ b/Runtime/GUI/UIQuad.cpp @@ -30,6 +30,8 @@ void UIQuad::Draw() m_Left, m_Top, // top-left }; + int n = sizeof(Vector2); + float uv[] = { 0, 0, 1, 0, diff --git a/Runtime/Lua/LuaBind/LuaBindInvoker.h b/Runtime/Lua/LuaBind/LuaBindInvoker.h index 5f24b15..cbfb2f9 100644 --- a/Runtime/Lua/LuaBind/LuaBindInvoker.h +++ b/Runtime/Lua/LuaBind/LuaBindInvoker.h @@ -59,6 +59,12 @@ namespace LuaBind udata.PushUserdata(state); ++argc; } + template<class T> + void AddLuaObject(T& obj) { + //LuaObjectTransfer::CastToLuaObject<T>(state, obj); + obj.CastToLuaObject(state); + ++argc; + } void Invoke(int nReturns = 0); diff --git a/Runtime/Lua/LuaBind/LuaBindLClass.h b/Runtime/Lua/LuaBind/LuaBindLClass.h index 296d6a1..538941e 100644 --- a/Runtime/Lua/LuaBind/LuaBindLClass.h +++ b/Runtime/Lua/LuaBind/LuaBindLClass.h @@ -14,4 +14,16 @@ namespace LuaBind };
+ class LuaObjectTransfer
+ {
+ public:
+ // 或者特化这些方法
+ template <class T>
+ static void CastToLuaObject(State&, T& in);
+
+ template <class T>
+ static void RestoreFromLuaObject(State& state, int index, T& out);
+
+ };
+
}
diff --git a/Runtime/Lua/LuaBind/LuaBindState.h b/Runtime/Lua/LuaBind/LuaBindState.h index e8ac42d..680f6e2 100644 --- a/Runtime/Lua/LuaBind/LuaBindState.h +++ b/Runtime/Lua/LuaBind/LuaBindState.h @@ -104,6 +104,10 @@ namespace LuaBind bool HasField(int idx, int name, int type); bool HasKeys(int idx); + template <class T> + void PushLuaObject(const T& obj) { + obj.CastToLuaObject(*this); + } void PushLuaObject(const ILuaClass& lc); void PushTable(const INativeTable& tb); void PushNil(); diff --git a/Runtime/Math/ITransData.h b/Runtime/Math/ITransData.h new file mode 100644 index 0000000..bda81e5 --- /dev/null +++ b/Runtime/Math/ITransData.h @@ -0,0 +1,7 @@ +//#pragma once
+//
+//class ITransData
+//{
+//public:
+// virtual int GetDataSize() = 0;
+//};
diff --git a/Runtime/Math/Vector2.h b/Runtime/Math/Vector2.h index f83a521..5dd8fe6 100644 --- a/Runtime/Math/Vector2.h +++ b/Runtime/Math/Vector2.h @@ -2,11 +2,12 @@ #include "MathHelper.h" #include "Runtime/Utilities/Assert.h" #include "Runtime/Lua/LuaHelper.h" +#include "ITransData.h" namespace Internal { template<typename T> - struct Vector2T : public LuaBind::ILuaClass + struct Vector2T { Vector2T(T x = 0, T y = 0) { @@ -50,7 +51,7 @@ namespace Internal return res; } - void CastToLuaObject(LuaBind::State& state) const override + void CastToLuaObject(LuaBind::State& state) const { int top = state.GetTop(); if (LuaHelper::GetLuaClass(state, "GameLab.Engine.Math.Vector2")) @@ -68,7 +69,7 @@ namespace Internal } } - void RestoreFromLuaObject(LuaBind::State& state, int index) override + void RestoreFromLuaObject(LuaBind::State& state, int index) { if (lua_isnil(state, index)) return; @@ -84,6 +85,11 @@ namespace Internal y = state.GetField<float>(index, 1, 0); } } + + static int GetDataSize() + { + return 2 * sizeof(T); + } T x, y; |