From a1f053229c1da8a0137e0d895f90b07eeb02ab91 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 22 Jul 2023 16:31:05 +0200 Subject: util.array: Fix new() library function --- spec/util_array_spec.lua | 7 +++++++ util/array.lua | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/util_array_spec.lua b/spec/util_array_spec.lua index ff049d0e..60c24753 100644 --- a/spec/util_array_spec.lua +++ b/spec/util_array_spec.lua @@ -1,6 +1,13 @@ local array = require "util.array"; describe("util.array", function () describe("creation", function () + describe("new", function () + it("works", function () + local a = array.new({"a", "b", "c"}); + assert.same({"a", "b", "c"}, a); + end); + end); + describe("from table", function () it("works", function () local a = array({"a", "b", "c"}); diff --git a/util/array.lua b/util/array.lua index aa06557d..074e9bc7 100644 --- a/util/array.lua +++ b/util/array.lua @@ -36,7 +36,9 @@ local function new_array(self, t, _s, _var) return setmetatable(t or {}, array_mt); end -array.new = new_array; +function array.new(t) + return setmetatable(t or {}, array_mt); +end function array_mt.__add(a1, a2) local res = new_array(); -- cgit v1.2.3