Comparison

util/array.lua @ 1373:120275376bbb

util.array: Add support for + operator to create a new array from two arrays joined
author Matthew Wild <mwild1@gmail.com>
date Sat, 20 Jun 2009 22:47:12 +0100
parent 1372:3b13bb57002e
child 1522:569d58d21612
comparison
equal deleted inserted replaced
1372:3b13bb57002e 1373:120275376bbb
1 local array = {}; 1 local array = {};
2 2
3 local array_mt = { __index = array, __tostring = function (array) return array:concat(", "); end }; 3 local array_mt = { __index = array, __tostring = function (array) return array:concat(", "); end };
4 local function new_array(_, t) 4 local function new_array(_, t)
5 return setmetatable(t or {}, array_mt); 5 return setmetatable(t or {}, array_mt);
6 end
7
8 function array_mt.__add(a1, a2)
9 local res = new_array();
10 return res:append(a1):append(a2);
6 end 11 end
7 12
8 setmetatable(array, { __call = new_array }); 13 setmetatable(array, { __call = new_array });
9 14
10 function array:map(func, t2) 15 function array:map(func, t2)