/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
3# This file illustrates the high level C++ interface.
4# In this case C++ classes work kind of like Tk widgets
5
6catch { load ./example.so example}
7catch { load ./example.dll example} ;# Windows
8
9# ----- Object creation -----
10
11puts "Creating some objects:"
12Circle c 10
13puts " Created circle [c cget -this]"
14Square s 10
15puts " Created square [s cget -this]"
16
17# ----- Access a static member -----
18
19puts "\nA total of $Shape_nshapes shapes were created"
20
21# ----- Member data access -----
22
23# Set the location of the object
24
25c configure -x 20 -y 30
26s configure -x -10 -y 5
27
28puts "\nHere is their current position:"
29puts " Circle = ([c cget -x], [c cget -y])"
30puts " Square = ([s cget -x], [s cget -y])"
31
32# ----- Call some methods -----
33
34puts "\nHere are some properties of the shapes:"
35foreach o "c s" {
36 puts " [$o cget -this]"
37 puts " area = [$o area]"
38 puts " perimeter = [$o perimeter]"
39}
40
41# ----- Delete everything -----
42
43puts "\nGuess I'll clean up now"
44
45# Note: this invokes the virtual destructor
46rename c ""
47rename s ""
48
49puts "$Shape_nshapes shapes remain"
50puts "Goodbye"
51