Advertisement
lvs

OOP concept

lvs
May 13th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.56 KB | None | 0 0
  1. local _M = {} -- module table
  2.  
  3. _M.someProperty = 1 -- class properties
  4.  
  5. local function createText()
  6.    -- local function are still valid, but not seen from outside - "private"
  7. end
  8.  
  9. local privateVar -- so do local variables
  10.  
  11. _GLOBAL_VAR -- without local it's global
  12.  
  13. function _M.staticMethod(vars)
  14.     -- this is class method like function (dot)
  15.     -- there is no "self"
  16. end
  17.  
  18. function _M:someMethod(vars)
  19.     -- this is object method like function (colon)
  20.     -- there is "self"
  21. end
  22.  
  23. return _M -- return this table as a module to require()
  24.  
  25. return _M
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement