1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
#include "LuaHelper.h"
#include "Runtime/Math/Vector2.h"
#include "Runtime/Math/Vector3.h"
#include "Runtime/Math/Vector4.h"
#include "Runtime/Math/Matrix44.h"
using namespace LuaBind;
template <>
Internal::Rect State::GetValue < Internal::Rect >(int idx, const Internal::Rect value)
{
Internal::Rect rect = value;
if (LuaHelper::IsType(*this, "GameLab.Engine.Math.Rect", idx))
{
rect.x = GetField<float>(idx, "x", 0);
rect.y = GetField<float>(idx, "y", 0);
rect.width = GetField<float>(idx, "z", 0);
rect.height = GetField<float>(idx, "w", 0);
}
else
{
rect.x = GetField<float>(idx, 1, 0);
rect.y = GetField<float>(idx, 2, 0);
rect.width = GetField<float>(idx, 3, 0);
rect.height = GetField<float>(idx, 4, 0);
}
return rect;
}
template <>
Internal::Vector2 State::GetValue < Internal::Vector2 >(int idx, const Internal::Vector2 value)
{
Internal::Vector2 v2 = value;
if (LuaHelper::IsType(*this, "GameLab.Engine.Math.Vector2", idx))
{
v2.x = GetField<float>(idx, "x", 0);
v2.y = GetField<float>(idx, "y", 0);
}
else
{
v2.x = GetField<float>(idx, 1, 0);
v2.y = GetField<float>(idx, 2, 0);
}
return v2;
}
template <>
Internal::Vector3 State::GetValue < Internal::Vector3 >(int idx, const Internal::Vector3 value)
{
Internal::Vector3 v3 = value;
if (LuaHelper::IsType(*this, "GameLab.Engine.Math.Vector3", idx))
{
v3.x = GetField<float>(idx, "x", 0);
v3.y = GetField<float>(idx, "y", 0);
v3.z = GetField<float>(idx, "z", 0);
}
else
{
v3.x = GetField<float>(idx, 1, 0);
v3.y = GetField<float>(idx, 2, 0);
v3.z = GetField<float>(idx, 3, 0);
}
return v3;
}
template <>
Internal::Vector4 State::GetValue < Internal::Vector4 >(int idx, const Internal::Vector4 value)
{
Internal::Vector4 v4 = value;
if (LuaHelper::IsType(*this, "GameLab.Engine.Math.Vector4", idx))
{
v4.x = GetField<float>(idx, "x", 0);
v4.y = GetField<float>(idx, "y", 0);
v4.z = GetField<float>(idx, "z", 0);
v4.w = GetField<float>(idx, "w", 0);
}
else
{
v4.x = GetField<float>(idx, 1, 0);
v4.y = GetField<float>(idx, 2, 0);
v4.z = GetField<float>(idx, 3, 0);
v4.w = GetField<float>(idx, 4, 0);
}
return v4;
}
template <>
Internal::Matrix44 State::GetValue < Internal::Matrix44 >(int idx, const Internal::Matrix44 value)
{
Internal::Matrix44 m4 = value;
if (LuaHelper::IsType(*this, "GameLab.Engine.Math.Matrix44", idx))
{
m4.m[0][0] = GetField<float>(idx, "m00", 0);
m4.m[0][1] = GetField<float>(idx, "m01", 0);
m4.m[0][2] = GetField<float>(idx, "m02", 0);
m4.m[0][3] = GetField<float>(idx, "m03", 0);
m4.m[1][0] = GetField<float>(idx, "m10", 0);
m4.m[1][1] = GetField<float>(idx, "m11", 0);
m4.m[1][2] = GetField<float>(idx, "m12", 0);
m4.m[1][3] = GetField<float>(idx, "m13", 0);
m4.m[2][0] = GetField<float>(idx, "m20", 0);
m4.m[2][1] = GetField<float>(idx, "m21", 0);
m4.m[2][2] = GetField<float>(idx, "m22", 0);
m4.m[2][3] = GetField<float>(idx, "m23", 0);
m4.m[3][0] = GetField<float>(idx, "m30", 0);
m4.m[3][1] = GetField<float>(idx, "m31", 0);
m4.m[3][2] = GetField<float>(idx, "m32", 0);
m4.m[3][3] = GetField<float>(idx, "m33", 0);
}
else
{
m4.m[0][0] = GetField<float>(idx, 1, 0);
m4.m[0][1] = GetField<float>(idx, 2, 0);
m4.m[0][2] = GetField<float>(idx, 3, 0);
m4.m[0][3] = GetField<float>(idx, 4, 0);
m4.m[1][0] = GetField<float>(idx, 5, 0);
m4.m[1][1] = GetField<float>(idx, 6, 0);
m4.m[1][2] = GetField<float>(idx, 7, 0);
m4.m[1][3] = GetField<float>(idx, 8, 0);
m4.m[2][0] = GetField<float>(idx, 9, 0);
m4.m[2][1] = GetField<float>(idx, 10, 0);
m4.m[2][2] = GetField<float>(idx, 11, 0);
m4.m[2][3] = GetField<float>(idx, 12, 0);
m4.m[3][0] = GetField<float>(idx, 13, 0);
m4.m[3][1] = GetField<float>(idx, 14, 0);
m4.m[3][2] = GetField<float>(idx, 15, 0);
m4.m[3][3] = GetField<float>(idx, 16, 0);
}
return m4;
}
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;
}
bool LuaHelper::InstantiateClass(LuaBind::State& state, const char* classFullName)
{
return false;
}
|