Software /
code /
prosody
Comparison
util/array.lua @ 1027:fe2e3d3dba6a
util.array: Add array.collect() to collect results from iterators into an array, and use module() to correctly set the module name
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 22 Apr 2009 17:46:17 +0100 |
parent | 922:0e45234360cd |
child | 1371:9e45bdf55353 |
comparison
equal
deleted
inserted
replaced
1026:e640df2e4e9b | 1027:fe2e3d3dba6a |
---|---|
50 self:push(self[i]); | 50 self:push(self[i]); |
51 self:pop(i); | 51 self:pop(i); |
52 end | 52 end |
53 end | 53 end |
54 | 54 |
55 _G.array = array | 55 function array.collect(f, s, var) |
56 local t, var = {}; | |
57 while true do | |
58 var = f(s, var); | |
59 if var == nil then break; end | |
60 table.insert(t, var); | |
61 end | |
62 return setmetatable(t, array_mt); | |
63 end | |
64 | |
65 _G.array = array; | |
66 module("array"); | |
67 | |
68 return array; |