Posted to tcl by aspect at Mon Nov 09 03:13:10 GMT 2015view raw

  1. oo::class create Light {
  2. method blink {} {
  3. puts "[self class] [self] blinking!"
  4. }
  5. }
  6.  
  7. oo::class create Fitting {
  8. variable nLights
  9. constructor {} {
  10. Light create Spot
  11. oo::objdefine [self] forward spot Spot
  12. }
  13. method addLight {} {
  14. Light create lamp[incr nLights]
  15. oo::objdefine [self] forward light$nLights lamp$nLights
  16. }
  17.  
  18. method light {n args} {
  19. lamp$n {*}$args
  20. }
  21.  
  22. method lights {args} {
  23. for {set n 1} {$n <= $nLights} {incr n} {
  24. my light$n {*}$args
  25. }
  26. }
  27. }
  28.  
  29. Fitting create strip
  30. strip addLight
  31. strip addLight
  32. strip light 1 blink
  33. strip light2 blink
  34. strip lights blink
  35.