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

« back to all changes in this revision

Viewing changes to Examples/python/pointer/example.py

  • 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: example.py
 
2
 
 
3
import example;
 
4
 
 
5
# First create some objects using the pointer library.
 
6
print "Testing the pointer library";
 
7
a = example.ptrcreate("int",37);
 
8
b = example.ptrcreate("int",42);
 
9
c = example.ptrcreate("int");  
 
10
 
 
11
print "     a =",a
 
12
print "     b =",b
 
13
print "     c =",c
 
14
 
 
15
# Call the add() function with some pointers
 
16
example.add(a,b,c)
 
17
 
 
18
# Now get the result
 
19
r = example.ptrvalue(c)
 
20
print "     37 + 42 =",r
 
21
 
 
22
# Clean up the pointers
 
23
example.ptrfree(a)
 
24
example.ptrfree(b)
 
25
example.ptrfree(c)
 
26
 
 
27
# Now try the typemap library
 
28
# This should be much easier. Now how it is no longer
 
29
# necessary to manufacture pointers.
 
30
 
 
31
print "Trying the typemap library";
 
32
r = example.sub(37,42)
 
33
print "     37 - 42 =",r
 
34
 
 
35
# Now try the version with multiple return values
 
36
 
 
37
print "Testing multiple return values";
 
38
q,r = example.divide(42,37)
 
39
print "     42/37 = %d remainder %d" % (q,r)
 
40
 
 
41
 
 
42