Comparison

util/array.lua @ 5564:1292643ac498

util.array: Wrap tostring() output in {} (otherwise empty arrays print as "").
author Waqas Hussain <waqas20@gmail.com>
date Tue, 07 May 2013 10:41:03 -0400
parent 5085:cbc7eb5cfa8c
child 5776:bd0ff8ae98a8
comparison
equal deleted inserted replaced
5563:678867c552d1 5564:1292643ac498
15 local tostring = tostring; 15 local tostring = tostring;
16 16
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(self, t, _s, _var) 22 local function new_array(self, t, _s, _var)
23 if type(t) == "function" then -- Assume iterator 23 if type(t) == "function" then -- Assume iterator
24 t = self.collect(t, _s, _var); 24 t = self.collect(t, _s, _var);
25 end 25 end