PageRenderTime 16ms CodeModel.GetById 1ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Examples/chicken/class/test-lowlevel-class.scm

#
Lisp | 76 lines | 52 code | 16 blank | 8 comment | 0 complexity | 6f994a91b31923c29f091b261b92ac63 MD5 | raw file
 1;; This file illustrates the low-level C++ interface generated
 2;; by SWIG.
 3
 4(load-library 'example "class.so")
 5(declare (uses example))
 6
 7;; ----- Object creation -----
 8
 9(display "Creating some objects:\n")
10(define c (new-Circle 10.0))
11(display "    Created circle ")
12(display c)
13(display "\n")
14(define s (new-Square 10.0))
15(display "    Created square ")
16(display s)
17(display "\n")
18
19;; ----- Access a static member -----
20
21(display "\nA total of ")
22(display (Shape-nshapes))
23(display " shapes were created\n")
24
25;; ----- Member data access -----
26
27;; Set the location of the object
28
29(Shape-x-set c 20.0)
30(Shape-y-set c 30.0)
31
32(Shape-x-set s -10.0)
33(Shape-y-set s 5.0)
34
35(display "\nHere is their current position:\n")
36(display "    Circle = (")
37(display (Shape-x-get c))
38(display ", ")
39(display (Shape-y-get c))
40(display ")\n")
41(display "    Square = (")
42(display (Shape-x-get s))
43(display ", ")
44(display (Shape-y-get s))
45(display ")\n")
46
47;; ----- Call some methods -----
48
49(display "\nHere are some properties of the shapes:\n")
50(let
51    ((disp (lambda (o)
52             (display "   ")
53             (display o)
54             (display "\n")
55             (display "        area      = ")
56             (display (Shape-area o))
57             (display "\n")
58             (display "        perimeter = ")
59             (display (Shape-perimeter o))
60             (display "\n"))))
61  (disp c)
62  (disp s))
63
64(display "\nGuess I'll clean up now\n")
65
66;; Note: this invokes the virtual destructor
67(set! c #f)
68(set! s #f)
69(gc #t)
70
71(set! s 3)
72(display (Shape-nshapes))
73(display " shapes remain\n")
74(display "Goodbye\n")
75
76(exit)