Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.62 KB | None | 0 0
  1. Mere = {Val1 = 10}
  2. function Mere.hello (text)
  3.   print("This is ",text)
  4. end
  5.  
  6. function Mere.increment(self,byV)
  7.   self.Val1 = self.Val1 + byV
  8. end
  9.  
  10. function Mere:new (o)
  11.   o = o or {}
  12.   setmetatable(o, self)
  13.   self.__index = self
  14.   return o
  15. end
  16.  
  17. m1 = Mere:new{Val1 = 100}
  18. --print(m1.Val1)
  19. m1:increment(10)
  20. --print(m1.Val1)
  21. --print(Mere.Val1)
  22.  
  23. Fille = Mere:new() --activate inheritence
  24. function Fille.HelloFille(self)
  25.   print("fille",self.Val1)
  26. end
  27.  
  28. f = Fille:new() --create instance of subclass
  29. f:HelloFille() --: call pass object (self) as first param
  30. f:increment(89)
  31. print(f.Val1)
  32.  
  33. print(Mere.hello("Cool"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement