fork download
  1. local Center = {}
  2.  
  3. function Center:new (o)
  4. o = o or {}
  5. setmetatable(o, self)
  6.  
  7. -- did you forgot this ?
  8. self.corners = {}
  9.  
  10. self.__index = self
  11. return o
  12. end
  13.  
  14. local Corner = {}
  15. function Corner:new()
  16. return {}
  17. end
  18.  
  19. local Map = {
  20. }
  21.  
  22. function Map:fill(points)
  23. self.centers = {}
  24. for k, pt in pairs(points) do
  25. self.centers[k] = Center:new() --<centers> is part of my Map object, and Center is an object
  26.  
  27. --repeats 4 times for each corner of a square
  28. local bottomleft = Corner:new()
  29. table.insert(self.centers[k].corners, bottomleft)
  30.  
  31. local bottomleft = Corner:new()
  32. table.insert(self.centers[k].corners, bottomleft)
  33.  
  34. local bottomleft = Corner:new()
  35. table.insert(self.centers[k].corners, bottomleft)
  36.  
  37. local bottomleft = Corner:new()
  38. table.insert(self.centers[k].corners, bottomleft)
  39. end
  40.  
  41. print(#self.centers[1].corners)
  42. end
  43.  
  44.  
  45. -- your code goes here
  46. local points = {{1,2}, {3,4}, {5,6}, {7,8}, {9,10}}
  47. Map:fill(points)
  48.  
Success #stdin #stdout 0s 14120KB
stdin
Standard input is empty
stdout
4