Advertisement
Gatesunder

Untitled

Jun 30th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.72 KB | None | 0 0
  1. -- Replace 'Class' (with capital C) with actual name of 'Class'
  2.  
  3. local class_mt = {}
  4. local object_mt = {}
  5. local object_idx = {}
  6. local Class = setmetatable({}, class_mt)
  7.  
  8. -- tells lua where to look for functions called by objects/instances of 'Class'
  9. object_mt.__index = object_idx
  10.  
  11. -- metamethods (aka operator overloading)
  12. function class_mt.__call(class, ...)
  13.     return class.new(...)
  14. end
  15. function object_mt.__eq(left, right)
  16.     return false
  17. end
  18.  
  19. -- example class function
  20. function object_idx:getId()
  21.     return self._id
  22. end
  23.  
  24. -- constructor
  25. function Class.new()
  26.     local self = setmetatable({}, object_mt)
  27.     return self
  28. end
  29.  
  30. -- returns a handle to the class definition so other files can use this class
  31. return Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement