Advertisement
FocusedWolf

Ahh! self == the instance

Sep 10th, 2011
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. class 'A'
  2.  
  3. local this
  4. function A:Initialize()
  5.     this = self
  6.     self.value = 0
  7. end
  8.  
  9. function A:DoMath()
  10.     self.value = self.value + 1
  11. end
  12.  
  13. function A:PrintValue()
  14.     Print(self.value)
  15. end
  16.  
  17. local a = A()
  18. a:Initialize()
  19.  
  20. a:PrintValue() //output = 0
  21. a.value = 20
  22. a:PrintValue() //output = 20
  23.  
  24. A.DoMath(a) //increment to 21
  25. a:DoMath()  //increment to 22
  26.  
  27. Print(ToString(a == this)) //output = true
  28.  
  29. Print(a.value) //output = 22
  30. a:PrintValue() //output = 22
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement