Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. -- Class declaration in Lua.
  2.  
  3. Foo = {}
  4.  
  5. -- constructor
  6. function Foo.new()
  7. return setmetatable({
  8.  
  9. -- attributes
  10. xyzzy = 42
  11.  
  12. }, {__index = Foo})
  13. end
  14.  
  15. -- methods
  16. function Foo:bar()
  17. -- self is this instance
  18. print(self.xyzzy)
  19. end
  20.  
  21. -- static methods
  22. function Foo.qux()
  23. print("Lua is awesome.")
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement