Guest User

Untitled

a guest
Feb 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. array = class {
  2. function(self, data)
  3. for k, v in pairs(data) do
  4. self[k] = v
  5. end
  6. end;
  7.  
  8. check = function(...)
  9. print(...)
  10. end;
  11.  
  12. each = function(self, func)
  13. for k, v in pairs(self) do
  14. func(v, k)
  15. end
  16. end;
  17.  
  18. map = function(self, func)
  19. local results = a{}
  20. for k, v in pairs(self) do
  21. results[k] = func(v, k)
  22. end
  23. return results
  24. end;
  25.  
  26. print = function(self)
  27. table.foreach(self, print)
  28. end;
  29.  
  30. ['.'] = function(self, key)
  31. if 'number' == type(key) then
  32. return self.data[key]
  33. else
  34. return self[key]
  35. end
  36. end;
  37.  
  38. ['.length'] = function(self)
  39.  
  40. end;
  41.  
  42. tostring = function(self)
  43. return table.show(self, 'array')
  44. end
  45. }
  46.  
  47. a = array
  48.  
  49.  
  50. list = a{1,2,3}
  51.  
  52. > print list
  53. // outputs
  54.  
  55. array = {
  56. [1] = 11;
  57. [2] = 22;
  58. [3] = 33;
  59. };
Add Comment
Please, Sign In to add comment