From d8417b03b9c2a820d3d3be0dfa80841b4d1f4c04 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 9 Nov 2021 19:22:13 +0800 Subject: *misc --- Runtime/Math/Vector2.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'Runtime/Math') 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 - 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 operator - (const Vector2T& v) const + { + Vector2T res = Vector2T(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 zero; -- cgit v1.1-26-g67d0