diff options
Diffstat (limited to 'Runtime/Math/Vector2.h')
-rw-r--r-- | Runtime/Math/Vector2.h | 27 |
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; |