summaryrefslogtreecommitdiff
path: root/Runtime/Math/Vector2.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-09 19:22:13 +0800
committerchai <chaifix@163.com>2021-11-09 19:22:13 +0800
commitd8417b03b9c2a820d3d3be0dfa80841b4d1f4c04 (patch)
tree7d036d283bd7a626d56c5c5a725733df439c8368 /Runtime/Math/Vector2.h
parent13f477664c07826c92eac774f0035994c460c057 (diff)
*misc
Diffstat (limited to 'Runtime/Math/Vector2.h')
-rw-r--r--Runtime/Math/Vector2.h27
1 files changed, 26 insertions, 1 deletions
diff --git a/Runtime/Math/Vector2.h b/Runtime/Math/Vector2.h
index 7c519b8..31098ab 100644
--- a/Runtime/Math/Vector2.h
+++ b/Runtime/Math/Vector2.h
@@ -1,11 +1,12 @@
#pragma once
#include "MathHelper.h"
#include "Runtime/Utilities/Assert.h"
+#include "Runtime/Lua/LuaHelper.h"
namespace Internal
{
template<typename T>
- struct Vector2T
+ struct Vector2T : public LuaBind::ILuaClass
{
Vector2T(T x = 0, T y = 0)
{
@@ -43,6 +44,30 @@ namespace Internal
return v.x != x || v.y != y;
}
+ Vector2T<T> operator - (const Vector2T& v) const
+ {
+ Vector2T<T> res = Vector2T<T>(x - v.x, y - v.y);
+ return res;
+ }
+
+ void CastToLuaObject(LuaBind::State& state) const override
+ {
+ int top = state.GetTop();
+ if (LuaHelper::GetLuaClass(state, "GameLab.Engine.Math.Vector2"))
+ {
+ lua_getfield(state, -1, "New");
+ lua_pushnumber(state, (float)x);
+ lua_pushnumber(state, (float)y);
+ state.Call(2, 1);
+ lua_replace(state, top + 1);
+ lua_settop(state, top + 1);
+ }
+ else
+ {
+ lua_pushnil(state);
+ }
+ }
+
T x, y;
static Vector2T<T> zero;