From f0697d6396d73aaff301ea5e2ea4ecb82877f0be Mon Sep 17 00:00:00 2001 From: Curtis Shmyr Date: Sun, 2 Oct 2016 16:22:50 -0600 Subject: [PATCH] Support subtraction of two CPos in Lua --- OpenRA.Game/CPos.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/CPos.cs b/OpenRA.Game/CPos.cs index bd94acfb1d..53aff1446d 100644 --- a/OpenRA.Game/CPos.cs +++ b/OpenRA.Game/CPos.cs @@ -83,11 +83,24 @@ namespace OpenRA public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right) { CPos a; - CVec b; - if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b)) - throw new LuaException("Attempted to call CPos.Subtract(CPos, CVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name)); + var rightType = right.WrappedClrType(); + if (!left.TryGetClrValue(out a)) + throw new LuaException("Attempted to call CPos.Subtract(CPos, (CPos|CVec)) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, rightType.Name)); - return new LuaCustomClrObject(a - b); + if (rightType == typeof(CPos)) + { + CPos b; + right.TryGetClrValue(out b); + return new LuaCustomClrObject(a - b); + } + else if (rightType == typeof(CVec)) + { + CVec b; + right.TryGetClrValue(out b); + return new LuaCustomClrObject(a - b); + } + + throw new LuaException("Attempted to call CPos.Subtract(CPos, (CPos|CVec)) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, rightType.Name)); } public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)