Advertisement
LastTalon

Object Oriented Library v.0.1.1

Jan 28th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.47 KB | None | 0 0
  1. local object = {}
  2.  
  3. function object:new(o)
  4.     o = o or {}
  5.     setmetatable(o, self)
  6.     self.__index = self
  7.     return o
  8. end
  9.  
  10. function object:clone()
  11.     local o = self:new(self)
  12.     return o
  13. end
  14.  
  15. function object:equals(o)
  16.     return self == o
  17. end
  18.  
  19. function object.__eq(a, b)
  20.     if a.equals then
  21.         return a:equals(b)
  22.     elseif b.equals then
  23.         return b.equals(a, b)
  24.     end
  25.     error("No such equality operator (==) exists for " .. a .. " or " .. b ..".")
  26.     return false
  27. end
  28.  
  29. return object
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement