util.array: Fix new() library function

Backport of ffe4adbd2af9 since new was added in the 0.12 branch
This commit is contained in:
Kim Alvefur 2023-07-22 16:31:05 +02:00
parent 683b90f871
commit 0fa9d6be37
2 changed files with 10 additions and 1 deletions

View file

@ -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"});

View file

@ -35,7 +35,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();