Changeset

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
parents 5084:82b9fe0c79c5
children 5086:1ef9aa0c9fb0 5087:71a5a6a6c74c
files util/array.lua
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/util/array.lua	Tue Aug 07 17:01:07 2012 +0200
+++ b/util/array.lua	Wed Aug 08 11:49:31 2012 +0100
@@ -19,7 +19,10 @@
 local array_methods = {};
 local array_mt = { __index = array_methods, __tostring = function (array) return array:concat(", "); end };
 
-local function new_array(_, t)
+local function new_array(self, t, _s, _var)
+	if type(t) == "function" then -- Assume iterator
+		t = self.collect(t, _s, _var);
+	end
 	return setmetatable(t or {}, array_mt);
 end