Advertisement
throwawayrobot

~/oop-test4.lua

Feb 24th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.82 KB | None | 0 0
  1. local object, id = require("object")
  2.  
  3. local Plan = {}
  4. function Plan:__construct(lua)
  5.   self.lua = lua
  6.   print(("[%s:Plan:construct()]: lua is: %s"):format(id(self), self.lua))
  7. end
  8. function Plan:__tostring()
  9.   return ("[%s:Plan:__tostring()]"):format(id(self))
  10. end
  11.  
  12. function Plan:method()
  13.   return ("[%s:Plan:method()]: lua is %s"):format(id(self), self.lua)
  14. end
  15.  
  16. print(("id(Plan): %s"):format(id(Plan)))
  17. print()
  18.  
  19. local plan1 = object(Plan, "fucking weird.")
  20. plan1.lua = 'weird'
  21. print(([[plan1:
  22.   id(plan1):        %s
  23.   tostring(plan1): %s
  24.   plan1:method():  %s
  25. ]]):format(id(plan1), tostring(plan1), plan1:method()))
  26.  
  27. local plan2 = object(Plan)
  28. plan2.lua = 'weirder'
  29. print(([[plan2:
  30.   id(plan2):        %s
  31.   tostring(plan2): %s
  32.   plan2:method():  %s
  33. ]]):format(id(plan2), tostring(plan2), plan2:method()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement