From 7fc55aa9a053810af68d088910933d760417318a Mon Sep 17 00:00:00 2001 From: Matthew Wilbern <39929480+fatboychummy@users.noreply.github.com> Date: Mon, 31 May 2021 06:58:46 -0600 Subject: [PATCH] Add __eq metamethod and equals method to the vector api. (#800) --- .../data/computercraft/lua/rom/apis/vector.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/resources/data/computercraft/lua/rom/apis/vector.lua b/src/main/resources/data/computercraft/lua/rom/apis/vector.lua index 05dab327e..6f0402ce3 100644 --- a/src/main/resources/data/computercraft/lua/rom/apis/vector.lua +++ b/src/main/resources/data/computercraft/lua/rom/apis/vector.lua @@ -151,6 +151,15 @@ local vector = { tostring = function(self) return self.x .. "," .. self.y .. "," .. self.z end, + + --- Check for equality between two vectors. + -- + -- @tparam Vector self The first vector to compare. + -- @tparam Vector other The second vector to compare to. + -- @treturn boolean Whether or not the vectors are equal. + equals = function(self, other) + return self.x == other.x and self.y == other.y and self.z == other.z + end, } local vmetatable = { @@ -161,6 +170,7 @@ local vmetatable = { __div = vector.div, __unm = vector.unm, __tostring = vector.tostring, + __eq = vector.equals, } --- Construct a new @{Vector} with the given coordinates.