~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Examples/tcl/class/example2.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2002-03-29 01:56:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020329015607-c0wt03xu8oy9ioj7
Tags: upstream-1.3.11
ImportĀ upstreamĀ versionĀ 1.3.11

Show diffs side-by-side

added added

removed removed

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