Skip to content

Instantly share code, notes, and snippets.

@speedmax
Created August 11, 2008 08:57
Show Gist options
  • Save speedmax/4832 to your computer and use it in GitHub Desktop.
Save speedmax/4832 to your computer and use it in GitHub Desktop.
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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment