import source from 1.3.40
[external/swig.git] / Examples / chicken / class / test-tinyclos-class.scm
1 ;; This file illustrates the proxy C++ interface generated
2 ;; by SWIG.
3
4 (load-library 'example "class_proxy.so")
5 (declare (uses example))
6 (declare (uses tinyclos))
7
8 ;; ----- Object creation -----
9
10 (display "Creating some objects:\n")
11 (define c (make <Circle> 10.0))
12 (display "    Created circle ")
13 (display c)
14 (display "\n")
15 (define s (make <Square> 10.0))
16 (display "    Created square ")
17 (display s)
18 (display "\n")
19
20 ;; ----- Access a static member -----
21
22 (display "\nA total of ")
23 (display (Shape-nshapes))
24 (display " shapes were created\n")
25
26 ;; ----- Member data access -----
27
28 ;; Set the location of the object
29
30 (slot-set! c 'x 20.0)
31 (slot-set! c 'y 30.0)
32
33 (slot-set! s 'x -10.0)
34 (slot-set! s 'y 5.0)
35
36 (display "\nHere is their current position:\n")
37 (display "    Circle = (")
38 (display (slot-ref c 'x))
39 (display ", ")
40 (display (slot-ref c 'y))
41 (display ")\n")
42 (display "    Square = (")
43 (display (slot-ref s 'x))
44 (display ", ")
45 (display (slot-ref s 'y))
46 (display ")\n")
47
48 ;; ----- Call some methods -----
49
50 (display "\nHere are some properties of the shapes:\n")
51 (let
52     ((disp (lambda (o)
53              (display "   ")
54              (display o)
55              (display "\n")
56              (display "        area      = ")
57              (display (area o))
58              (display "\n")
59              (display "        perimeter = ")
60              (display (perimeter o))
61              (display "\n"))))
62   (disp c)
63   (disp s))
64
65 (display "\nGuess I'll clean up now\n")
66
67 ;; Note: Invoke the virtual destructors by forcing garbage collection
68 (set! c 77)
69 (set! s 88)
70 (gc #t)
71
72 (display (Shape-nshapes))
73 (display " shapes remain\n")
74 (display "Goodbye\n")
75
76 (exit)