Diff

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
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