*** empty log message ***
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@50 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
bcef419b66
commit
16ac3b10f8
16 changed files with 517 additions and 0 deletions
18
SWIG/Examples/python/simple/Makefile
Normal file
18
SWIG/Examples/python/simple/Makefile
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='mypython' INTERFACE='$(INTERFACE)' python_static
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.o *~ *.so mypython *.pyc .~* core
|
||||
|
||||
|
||||
1
SWIG/Examples/python/simple/README
Normal file
1
SWIG/Examples/python/simple/README
Normal file
|
|
@ -0,0 +1 @@
|
|||
Simple example from the users manual
|
||||
21
SWIG/Examples/python/simple/example.c
Normal file
21
SWIG/Examples/python/simple/example.c
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* Simple example from documentation */
|
||||
/* File : example.c */
|
||||
|
||||
#include <time.h>
|
||||
|
||||
double My_variable = 3.0;
|
||||
|
||||
int fact(int n) {
|
||||
if (n <= 1) return 1;
|
||||
else return n*fact(n-1);
|
||||
}
|
||||
|
||||
int mod(int n, int m) {
|
||||
return (n % m);
|
||||
}
|
||||
|
||||
char *get_time() {
|
||||
long ltime;
|
||||
time(<ime);
|
||||
return ctime(<ime);
|
||||
}
|
||||
8
SWIG/Examples/python/simple/example.i
Normal file
8
SWIG/Examples/python/simple/example.i
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
extern double My_variable;
|
||||
extern int fact(int);
|
||||
extern int mod(int n, int m);
|
||||
extern char *get_time();
|
||||
|
||||
30
SWIG/Examples/python/simple/example.py
Normal file
30
SWIG/Examples/python/simple/example.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#!/home/sci/local/bin/python
|
||||
#
|
||||
# Python test script. This also illustrates the use of get/set
|
||||
# for C variables.
|
||||
|
||||
from example import *
|
||||
print get_time()
|
||||
print "My Variable = ", cvar.My_variable
|
||||
for i in range(0,14):
|
||||
n = fact(i)
|
||||
print i, "factorial is ", n
|
||||
|
||||
for i in range(1,250):
|
||||
for j in range(1,250):
|
||||
n = mod(i,j)
|
||||
cvar.My_variable = cvar.My_variable + n
|
||||
|
||||
print "My_variable = ", cvar.My_variable
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue