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

« back to all changes in this revision

Viewing changes to Examples/r/class/runme.R

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2006-12-20 14:43:24 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061220144324-bps3kb06xp5oy9w1
Tags: 1.3.31-1ubuntu1
* Merge from debian unstable, remaining changes:
  - drop support for pike
  - use php5 instead of php4
  - clean Runtime/ as well
  - force a few environment variables

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This file illustrates the shadow-class C++ interface generated
 
2
# by SWIG.
 
3
 
 
4
dyn.load('example_wrap.so')
 
5
source('example_wrap.R')
 
6
cacheMetaData(1)
 
7
 
 
8
# ----- Object creation -----
 
9
 
 
10
print("Creating some objects:")
 
11
circle <- Circle(10)
 
12
print ("    Created circle")
 
13
square <- Square(10)
 
14
print ("    Created square")
 
15
 
 
16
# ----- Access a static member -----
 
17
 
 
18
sprintf("A total of %d shapes were created", Shape_nshapes())
 
19
 
 
20
# ----- Member data access -----
 
21
 
 
22
# Set the location of the object
 
23
 
 
24
circle$x <- 20
 
25
circle$y <- 30
 
26
 
 
27
square$x <- -10
 
28
square$y <- 5
 
29
 
 
30
print("Here is their current position:")
 
31
sprintf("    Circle = (%f, %f)", circle$x,circle$y)
 
32
sprintf("    Square = (%f, %f)", square$x,square$y)
 
33
 
 
34
# ----- Call some methods -----
 
35
 
 
36
print ("Here are some properties of the shapes:")
 
37
 
 
38
sapply(c(circle, square), 
 
39
                 function(o) {
 
40
sprintf("       area = %f perimeter = %f", o$area(),  o$perimeter())
 
41
})
 
42
 
 
43
print("Guess I'll clean up now")
 
44
delete(circle)
 
45
delete(square)
 
46
 
 
47
sprintf("%d shapes remain", Shape_nshapes())
 
48
print ("Goodbye");
 
49