Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- array = class {
- function(self, data)
- for k, v in pairs(data) do
- self[k] = v
- end
- end;
- check = function(...)
- print(...)
- end;
- each = function(self, func)
- for k, v in pairs(self) do
- func(v, k)
- end
- end;
- map = function(self, func)
- local results = a{}
- for k, v in pairs(self) do
- results[k] = func(v, k)
- end
- return results
- end;
- print = function(self)
- table.foreach(self, print)
- end;
- ['.'] = function(self, key)
- if 'number' == type(key) then
- return self.data[key]
- else
- return self[key]
- end
- end;
- ['.length'] = function(self)
- end;
- tostring = function(self)
- return table.show(self, 'array')
- end
- }
- a = array
- list = a{1,2,3}
- > print list
- // outputs
- array = {
- [1] = 11;
- [2] = 22;
- [3] = 33;
- };
Add Comment
Please, Sign In to add comment