Comparison

util/array.lua @ 9487:4e38121a349d

util.array: Add freeze metamethod
author Kim Alvefur <zash@zash.se>
date Fri, 12 Oct 2018 00:51:52 +0200
parent 8521:6f5ce0f09f40
child 9528:1af7cc3b9747
comparison
equal deleted inserted replaced
9486:20aad0108999 9487:4e38121a349d
18 18
19 local array = {}; 19 local array = {};
20 local array_base = {}; 20 local array_base = {};
21 local array_methods = {}; 21 local array_methods = {};
22 local array_mt = { __index = array_methods, __name = "array", __tostring = function (self) return "{"..self:concat(", ").."}"; end }; 22 local array_mt = { __index = array_methods, __name = "array", __tostring = function (self) return "{"..self:concat(", ").."}"; end };
23
24 function array_mt:__freeze() return self; end
23 25
24 local function new_array(self, t, _s, _var) 26 local function new_array(self, t, _s, _var)
25 if type(t) == "function" then -- Assume iterator 27 if type(t) == "function" then -- Assume iterator
26 t = self.collect(t, _s, _var); 28 t = self.collect(t, _s, _var);
27 end 29 end