From afd279f1db60e582d96831379fc7539b555e55a2 Mon Sep 17 00:00:00 2001 From: Max Cahill <1bardesign@gmail.com> Date: Wed, 8 Apr 2020 21:10:03 +1000 Subject: [PATCH] [added] tostring for vec2 and vec3 - not sure how to handle wanting more/less precision for these currently. --- vec2.lua | 5 +++++ vec3.lua | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/vec2.lua b/vec2.lua index 45f5764..31657ac 100644 --- a/vec2.lua +++ b/vec2.lua @@ -9,6 +9,11 @@ local math = require(path .. "mathx") --shadow global math module local vec2 = class() vec2.type = "vec2" +--stringification +vec2.__mt.__tostring = function(self) + return ("(%.2f, %.2f)"):format(self.x, self.y) +end + --probably-too-flexible ctor function vec2:new(x, y) if x and y then diff --git a/vec3.lua b/vec3.lua index 2ff4b19..400b559 100644 --- a/vec3.lua +++ b/vec3.lua @@ -11,6 +11,11 @@ local math = require(path .. "mathx") --shadow global math module local vec3 = class() vec3.type = "vec3" +--stringification +vec2.__mt.__tostring = function(self) + return ("(%.2f, %.2f, %.2f)"):format(self.x, self.y, self.z) +end + --probably-too-flexible ctor function vec3:new(x, y, z) if x and y and z then