Software /
code /
prosody
Comparison
util/array.lua @ 5085:cbc7eb5cfa8c
util.array: Accept an iterator to the array constructor
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 08 Aug 2012 11:49:31 +0100 |
parent | 4449:ca74d8ed1a15 |
child | 5564:1292643ac498 |
comparison
equal
deleted
inserted
replaced
5084:82b9fe0c79c5 | 5085:cbc7eb5cfa8c |
---|---|
17 local array = {}; | 17 local array = {}; |
18 local array_base = {}; | 18 local array_base = {}; |
19 local array_methods = {}; | 19 local array_methods = {}; |
20 local array_mt = { __index = array_methods, __tostring = function (array) return array:concat(", "); end }; | 20 local array_mt = { __index = array_methods, __tostring = function (array) return array:concat(", "); end }; |
21 | 21 |
22 local function new_array(_, t) | 22 local function new_array(self, t, _s, _var) |
23 if type(t) == "function" then -- Assume iterator | |
24 t = self.collect(t, _s, _var); | |
25 end | |
23 return setmetatable(t or {}, array_mt); | 26 return setmetatable(t or {}, array_mt); |
24 end | 27 end |
25 | 28 |
26 function array_mt.__add(a1, a2) | 29 function array_mt.__add(a1, a2) |
27 local res = new_array(); | 30 local res = new_array(); |