Updated formatting of documentation plus a little reorganization.
[cmake.git] / Tests / SwigTest / runme2.tcl
blob88ec2f678dccd66929e71c3d2ee31263fb6d8825
1 # file: runme2.tcl
3 # This file illustrates the low-level C++ interface
4 # created by SWIG. In this case, all of our C++ classes
5 # get converted into function calls.
7 catch { load ./example[info sharedlibextension] example}
9 # ----- Object creation -----
11 puts "Creating some objects:"
12 set c [new_Circle 10]
13 puts " Created circle $c"
14 set s [new_Square 10]
15 puts " Created square $s"
17 # ----- Access a static member -----
19 puts "\nA total of $Shape_nshapes shapes were created"
21 # ----- Member data access -----
23 # Set the location of the object
24 # Note: the base class must be used since that's where x and y
25 # were declared.
27 Shape_x_set $c 20
28 Shape_y_set $c 30
29 Shape_x_set $s -10
30 Shape_y_set $s 5
32 puts "\nHere is their current position:"
33 puts " Circle = ([Shape_x_get $c], [Shape_y_get $c])"
34 puts " Square = ([Shape_x_get $s], [Shape_y_get $s])"
36 # ----- Call some methods -----
38 puts "\nHere are some properties of the shapes:"
39 foreach o "$c $s" {
40 puts " $o"
41 puts " area = [Shape_area $o]"
42 puts " perimeter = [Shape_perimeter $o]"
44 # Notice how the Shape_area() and Shape_perimeter() functions really
45 # invoke the appropriate virtual method on each object.
47 # ----- Try to cause a type error -----
49 puts "\nI'm going to try and break the type system"
51 if { [catch {
52 # Bad script!
53 Square_area $c # Try to invoke Square method on a Circle
54 puts " Bad bad SWIG!"
56 }]} {
57 puts " Well, it didn't work. Good SWIG."
60 # ----- Delete everything -----
62 puts "\nGuess I'll clean up now"
64 # Note: this invokes the virtual destructor
65 delete_Shape $c
66 delete_Shape $s
68 puts "$Shape_nshapes shapes remain"
69 puts "Goodbye"