Posted to tcl by lua at Tue Jun 28 00:46:39 GMT 2011view raw

  1. require "object"
  2.  
  3. x = Object { f1 = "x.f1" }
  4.  
  5. function x:print1(stg)
  6. print("stg is ", stg, " and f1 is ", self.f1)
  7. end
  8.  
  9.  
  10.  
  11. w = x { f1 = "w.f1"; f2 = "w.f2" }
  12.  
  13. function w:print2(stg)
  14. print("stg is ", stg, " and f2 is ", self.f2)
  15. end
  16.  
  17.  
  18. x1 = x {}
  19. x1.f1 = "no longer x.f1"
  20. x1:print1("from x1")
  21.  
  22. x2 = x {}
  23. x2:print1("from x2")
  24.  
  25. w1 = w {}
  26. w1:print1("from w1")
  27. w1:print2("from w1")
  28.