From 57e7d4c4883d4e22eb213fdd411c051d186caf86 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 26 May 2024 15:42:15 +0200 Subject: [PATCH] Add polyfill for vector.copy() closes #246 You could say I am doing this against better judgement, but this is really a simple and easy fix for my problem. --- .luacheckrc | 7 ++++++- worldedit/common.lua | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/.luacheckrc b/.luacheckrc index 76e0696..e9f95fc 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -7,7 +7,9 @@ read_globals = { vector = {fields = { -- as of 5.0 "new", "direction", "distance", "length", "normalize", "floor", "round", - "apply", "equals", "sort", "add", "subtract", "multiply", "divide" + "apply", "equals", "sort", "add", "subtract", "multiply", "divide", + -- polyfilled + "copy" }}, } globals = {"worldedit"} @@ -15,6 +17,9 @@ globals = {"worldedit"} -- Ignore these errors until someone decides to fix them ignore = {"212", "213", "411", "412", "421", "422", "431", "432", "631"} +files["worldedit/common.lua"] = { + globals = {"vector"}, +} files["worldedit/test"] = { read_globals = {"testnode1", "testnode2", "testnode3", "area", "check", "place_pattern"}, } diff --git a/worldedit/common.lua b/worldedit/common.lua index 4ac6ade..55b10f1 100644 --- a/worldedit/common.lua +++ b/worldedit/common.lua @@ -1,6 +1,15 @@ --- Common functions [INTERNAL]. All of these functions are internal! -- @module worldedit.common +-- Polyfill for vector.copy (added in 5.5.0) +if not vector.copy then + local vnew = vector.new + vector.copy = function(v) + return vnew(v.x, v.y, v.z) + end +end + + --- Copies and modifies positions `pos1` and `pos2` so that each component of -- `pos1` is less than or equal to the corresponding component of `pos2`. -- Returns the new positions.