Software /
code /
prosody
Changeset
13247:1bb4aa803b32 0.12
util.array: Fix new() library function
Backport of ffe4adbd2af9 since new was added in the 0.12 branch
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 22 Jul 2023 16:31:05 +0200 |
parents | 13219:22763b30e458 |
children | 13248:db433ed3135c 13254:a2ba3f06dcf4 |
files | spec/util_array_spec.lua util/array.lua |
diffstat | 2 files changed, 10 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/spec/util_array_spec.lua Mon Jul 17 14:56:57 2023 +0200 +++ b/spec/util_array_spec.lua Sat Jul 22 16:31:05 2023 +0200 @@ -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"});
--- a/util/array.lua Mon Jul 17 14:56:57 2023 +0200 +++ b/util/array.lua Sat Jul 22 16:31:05 2023 +0200 @@ -35,7 +35,9 @@ 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();