diff options
author | chai <chaifix@163.com> | 2021-11-05 14:25:39 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-11-05 14:25:39 +0800 |
commit | 2b9621a46288532b352b7838f96aca80f971e3d1 (patch) | |
tree | 6131ef5484e4f6d4c14c541b65a107869e3b112e /Runtime/Lua | |
parent | 6d5787d8da9ad1685864668dd4c3d6aa73a563db (diff) |
*misc
Diffstat (limited to 'Runtime/Lua')
-rw-r--r-- | Runtime/Lua/LuaHelper.cpp | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/Runtime/Lua/LuaHelper.cpp b/Runtime/Lua/LuaHelper.cpp index 951f2fe..f1dc349 100644 --- a/Runtime/Lua/LuaHelper.cpp +++ b/Runtime/Lua/LuaHelper.cpp @@ -2,6 +2,7 @@ #include "Runtime/Math/Math.h" #include "Runtime/GUI/Font.h"
+#include "Runtime/Graphics/Color.h"
using namespace LuaBind;
@@ -16,7 +17,7 @@ Rect State::GetValue < Rect >(int idx, const Rect value) rect.width = GetField<float>(idx, "z", 0);
rect.height = GetField<float>(idx, "w", 0);
}
- else
+ else if (LuaHelper::IsType(*this, "table", idx))
{
rect.x = GetField<float>(idx, 1, 0);
rect.y = GetField<float>(idx, 2, 0);
@@ -35,7 +36,7 @@ Vector2 State::GetValue < Vector2 >(int idx, const Vector2 value) v2.x = GetField<float>(idx, "x", 0);
v2.y = GetField<float>(idx, "y", 0);
}
- else
+ else if (LuaHelper::IsType(*this, "table", idx))
{
v2.x = GetField<float>(idx, 1, 0);
v2.y = GetField<float>(idx, 2, 0);
@@ -53,7 +54,7 @@ Vector3 State::GetValue < Vector3 >(int idx, const Vector3 value) v3.y = GetField<float>(idx, "y", 0);
v3.z = GetField<float>(idx, "z", 0);
}
- else
+ else if (LuaHelper::IsType(*this, "table", idx))
{
v3.x = GetField<float>(idx, 1, 0);
v3.y = GetField<float>(idx, 2, 0);
@@ -73,7 +74,7 @@ Vector4 State::GetValue < Vector4 >(int idx, const Vector4 value) v4.z = GetField<float>(idx, "z", 0);
v4.w = GetField<float>(idx, "w", 0);
}
- else
+ else if (LuaHelper::IsType(*this, "table", idx))
{
v4.x = GetField<float>(idx, 1, 0);
v4.y = GetField<float>(idx, 2, 0);
@@ -84,6 +85,34 @@ Vector4 State::GetValue < Vector4 >(int idx, const Vector4 value) }
template <>
+Color32 State::GetValue < Color32 >(int idx, const Color32 value)
+{
+ Color32 col = value;
+ if (LuaHelper::IsType(*this, "GameLab.Engine.Rendering.Color", idx))
+ {
+ col.r = GetField<float>(idx, "r", 0) * 255.f;
+ col.g = GetField<float>(idx, "g", 0) * 255.f;
+ col.b = GetField<float>(idx, "b", 0) * 255.f;
+ col.a = GetField<float>(idx, "a", 0) * 255.f;
+ }
+ else if (LuaHelper::IsType(*this, "GameLab.Engine.Rendering.Color32", idx))
+ {
+ col.r = GetField<int>(idx, "r", 0);
+ col.g = GetField<int>(idx, "g", 0);
+ col.b = GetField<int>(idx, "b", 0);
+ col.a = GetField<int>(idx, "a", 0);
+ }
+ else if(LuaHelper::IsType(*this, "table", idx))
+ {
+ col.r = GetField<float>(idx, 1, 0);
+ col.g = GetField<float>(idx, 2, 0);
+ col.b = GetField<float>(idx, 3, 0);
+ col.a = GetField<float>(idx, 4, 0);
+ }
+ return col;
+}
+
+template <>
Matrix44 State::GetValue < Matrix44 >(int idx, const Matrix44 value)
{
Matrix44 m4 = value;
@@ -109,7 +138,7 @@ Matrix44 State::GetValue < Matrix44 >(int idx, const Matrix44 value) m4.m[3][2] = GetField<float>(idx, "m32", 0);
m4.m[3][3] = GetField<float>(idx, "m33", 0);
}
- else
+ else if (LuaHelper::IsType(*this, "table", idx))
{
m4.m[0][0] = GetField<float>(idx, 1, 0);
m4.m[0][1] = GetField<float>(idx, 2, 0);
@@ -159,6 +188,8 @@ bool LuaHelper::IsType(LuaBind::State& state, const char* typeName, int idx) {
int top = state.GetTop();
cc8* type = luaL_typename(state, idx);
+ if (strcmp(type, "nil") == 0 || strcmp(type, "no value") == 0)
+ return false;
if (strcmp(type, typeName) == 0)
return true;
state.GetField(idx, "_type");
|