PageRenderTime 57ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/ttn-post-libtool-1-4-3-upgrade/SWIG/Examples/tcl/class/example2.tcl

#
TCL | 51 lines | 28 code | 14 blank | 9 comment | 0 complexity | 0475245900211df638a688087d573536 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. # file: example1.tcl
  2. # This file illustrates the high level C++ interface.
  3. # In this case C++ classes work kind of like Tk widgets
  4. catch { load ./example.so example}
  5. catch { load ./example.dll example} ;# Windows
  6. # ----- Object creation -----
  7. puts "Creating some objects:"
  8. Circle c 10
  9. puts " Created circle [c cget -this]"
  10. Square s 10
  11. puts " Created square [s cget -this]"
  12. # ----- Access a static member -----
  13. puts "\nA total of $Shape_nshapes shapes were created"
  14. # ----- Member data access -----
  15. # Set the location of the object
  16. c configure -x 20 -y 30
  17. s configure -x -10 -y 5
  18. puts "\nHere is their current position:"
  19. puts " Circle = ([c cget -x], [c cget -y])"
  20. puts " Square = ([s cget -x], [s cget -y])"
  21. # ----- Call some methods -----
  22. puts "\nHere are some properties of the shapes:"
  23. foreach o "c s" {
  24. puts " [$o cget -this]"
  25. puts " area = [$o area]"
  26. puts " perimeter = [$o perimeter]"
  27. }
  28. # ----- Delete everything -----
  29. puts "\nGuess I'll clean up now"
  30. # Note: this invokes the virtual destructor
  31. rename c ""
  32. rename s ""
  33. puts "$Shape_nshapes shapes remain"
  34. puts "Goodbye"