*** 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
253
SWIG/Examples/Makefile.in
Normal file
253
SWIG/Examples/Makefile.in
Normal file
|
|
@ -0,0 +1,253 @@
|
|||
# ------------------------------------------------------------
|
||||
# SWIG Makefile Template
|
||||
#
|
||||
# This file is used by all of the examples to build modules
|
||||
# and other things. You can use this as a starting point
|
||||
# for building your own modules.
|
||||
#
|
||||
# How to use this Makefile:
|
||||
#
|
||||
# 1. Assuming you ran 'configure', some values in this Makefile
|
||||
# will be set automatically for you. Configure will try to
|
||||
# guess how to do certain things such as build shared libraries,
|
||||
# etc... Unfortunately, it's not perfect so you may need to
|
||||
# change some things by hand (see next).
|
||||
#
|
||||
# 2. Take a look at the prefixes below. Since SWIG works with
|
||||
# multiple target languages, you may need to find out where
|
||||
# certain packages have been installed. Set the prefixes
|
||||
# accordingly. I've set the prefixes assuming that SWIG has
|
||||
# been installed in the same directory as the target languages.
|
||||
#
|
||||
# 3. To use this makefile, simply set SRCS, INTERFACE, INCLUDE, LIBS,
|
||||
# TARGET, and do a
|
||||
# $(MAKE) -f Makefile.template.in SRCS='$(SRCS)' \
|
||||
# INCLUDE='$(INCLUDE) LIBS='$(LIBS)' INTERFACE='$(INTERFACE)' \
|
||||
# TARGET='$(TARGET)' method
|
||||
#
|
||||
# 'method' describes what is being built.
|
||||
#
|
||||
#---------------------------------------------------------------
|
||||
|
||||
TARGET =
|
||||
CC = @CC@
|
||||
CXX = @CXX@
|
||||
CFLAGS =
|
||||
prefix = @prefix@
|
||||
exec_prefix= @exec_prefix@
|
||||
SRCS =
|
||||
INCLUDE =
|
||||
LIBS =
|
||||
INTERFACE =
|
||||
SWIGOPT =
|
||||
SWIG = SWIG
|
||||
|
||||
LIBM = @LIBM@
|
||||
LIBC = @LIBC@
|
||||
LIBCRYPT = @LIBCRYPT@
|
||||
SYSLIBS = $(LIBM) $(LIBC) $(LIBCRYPT)
|
||||
|
||||
# X11 options
|
||||
|
||||
XLIB = @XLIBSW@
|
||||
XINCLUDE = @XINCLUDES@
|
||||
|
||||
ISRCS = $(INTERFACE:.i=_wrap.c)
|
||||
|
||||
##################################################################
|
||||
# Dynamic loading for C++
|
||||
# If you are going to be building dynamic loadable modules in C++,
|
||||
# you may need to edit this line appropriately.
|
||||
#
|
||||
# This line works for g++, but I'm not sure what it might be
|
||||
# for other C++ compilers
|
||||
##################################################################
|
||||
|
||||
CPP_DLLIBS = #-L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \
|
||||
-L/usr/local/lib -lg++ -lstdc++ -lgcc
|
||||
|
||||
|
||||
# Symbols used for using shared libraries
|
||||
SO= @SO@
|
||||
LDSHARED= @LDSHARED@
|
||||
CCSHARED= @CCSHARED@
|
||||
CXXSHARED= @LDSHARED@
|
||||
|
||||
# This is used for building shared libraries with a number of C++
|
||||
# compilers. If it doesn't work, comment it out.
|
||||
|
||||
CXXSHARED= @CXX@ -shared
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
IOBJS = $(ISRCS:.c=.o)
|
||||
|
||||
##################################################################
|
||||
##### Tcl/Tk ######
|
||||
##################################################################
|
||||
|
||||
# Set these to your local copy of Tcl/Tk.
|
||||
|
||||
TCL_INCLUDE = @TCLINCLUDE@
|
||||
TCL_LIB = @TCLLIB@
|
||||
TCL_OPTS = -ltcl @LIBS@
|
||||
TK_OPTS = -ltk -ltcl @LIBS@
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Build a new version of the tclsh shell
|
||||
# -----------------------------------------------------------
|
||||
|
||||
|
||||
tclsh: $(SRCS)
|
||||
$(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) -ltclsh.i $(INTERFACE)
|
||||
$(CC) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(TCL_INCLUDE) \
|
||||
$(TCL_LIB) $(TCL_OPTS) $(LIBS) $(SYSLIBS) -o $(TARGET)
|
||||
|
||||
tclsh_cpp: $(SRCS)
|
||||
$(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) -ltclsh.i $(INTERFACE)
|
||||
$(CXX) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(TCL_INCLUDE) \
|
||||
$(TCL_LIB) $(TCL_OPTS) $(LIBS) $(SYSLIBS) -o $(TARGET)
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Build a new copy of wish
|
||||
# -----------------------------------------------------------
|
||||
|
||||
wish: $(SRCS)
|
||||
$(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) -lwish.i $(INTERFACE)
|
||||
$(CC) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(TCL_INCLUDE) \
|
||||
$(XINCLUDE) $(TCL_LIB) $(TK_OPTS) $(XLIB) $(LIBS) $(SYSLIBS) -o $(TARGET)
|
||||
|
||||
|
||||
wish_cpp: $(SRCS)
|
||||
$(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) -lwish.i $(INTERFACE)
|
||||
$(CXX) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(TCL_INCLUDE) \
|
||||
$(XINCLUDE) $(TCL_LIB) $(TK_OPTS) $(XLIB) $(LIBS) $(SYSLIBS) -o $(TARGET)
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Build a Tcl dynamic loadable module (you might need to tweak this)
|
||||
# -----------------------------------------------------------
|
||||
|
||||
tcldl: $(SRCS)
|
||||
$(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) $(INTERFACE)
|
||||
$(CC) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(TCL_INCLUDE)
|
||||
$(LDSHARED) $(OBJS) $(IOBJS) $(LIBS) -o $(TARGET)$(SO)
|
||||
|
||||
# -----------------------------------------------------------
|
||||
# Build a Tcl7.5 dynamic loadable module for C++
|
||||
# -----------------------------------------------------------
|
||||
|
||||
tcldl_cpp: $(SRCS)
|
||||
$(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) $(INTERFACE)
|
||||
$(CXX) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(TCL_INCLUDE)
|
||||
$(CXXSHARED) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(TARGET)$(SO)
|
||||
|
||||
##################################################################
|
||||
##### PERL 5 ######
|
||||
##################################################################
|
||||
|
||||
# You need to set this variable to the Perl5 directory containing the
|
||||
# files "perl.h", "EXTERN.h" and "XSUB.h". With Perl5.003, it's
|
||||
# usually something like /usr/local/lib/perl5/arch-osname/5.003/CORE.
|
||||
|
||||
PERL5_INCLUDE= @PERL5EXT@
|
||||
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# Build a Perl5 dynamically loadable module (C)
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
perl5: $(SRCS)
|
||||
$(SWIG) -perl5 $(SWIGOPT) $(INTERFACE)
|
||||
$(CC) -c -Dbool=char $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) -I$(PERL5_INCLUDE)
|
||||
$(LDSHARED) $(OBJS) $(IOBJS) $(LIBS) -o $(TARGET)$(SO)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# Build a Perl5 dynamically loadable module (C++)
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
perl5_cpp: $(SRCS)
|
||||
$(SWIG) -perl5 -c++ $(SWIGOPT) $(INTERFACE)
|
||||
$(CXX) -c $(CCSHARED) $(CFLAGS) -Dexplicit= $(SRCS) $(ISRCS) $(INCLUDE) -I$(PERL5_INCLUDE)
|
||||
$(CXXSHARED) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(TARGET)$(SO)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# Build a module from existing XS C source code. (ie. from xsubpp).
|
||||
# ----------------------------------------------------------------
|
||||
perl5_xs: $(SRCS)
|
||||
$(CC) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(INCLUDE) -I$(PERL5_INCLUDE)
|
||||
$(LDSHARED) $(OBJS) $(LIBS) -o $(TARGET)$(SO)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# Build a statically linked Perl5 executable
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
PERL5_LIB = -L$(PERL5_INCLUDE) -lperl @LIBS@ $(SYSLIBS)
|
||||
|
||||
perl5_static: $(SRCS)
|
||||
$(SWIG) -perl5 -static -lperlmain.i $(SWIGOPT) $(INTERFACE)
|
||||
$(CC) $(CFLAGS) -Dbool=char $(SRCS) $(ISRCS) $(INCLUDE) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET)
|
||||
|
||||
perl5_static_cpp: $(SRCS)
|
||||
$(SWIG) -perl5 -c++ -static -lperlmain.i $(SWIGOPT) $(INTERFACE)
|
||||
$(CXX) $(CFLAGS) -Dexplicit= $(SRCS) $(ISRCS) $(INCLUDE) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET)
|
||||
|
||||
|
||||
##################################################################
|
||||
##### PYTHON ######
|
||||
##################################################################
|
||||
|
||||
# Make sure these locate your Python installation
|
||||
PYTHON_INCLUDE= -DHAVE_CONFIG_H @PYINCLUDE@
|
||||
PYTHON_LIB = @PYLIB@
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# Build a C dynamically loadable module
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
python: $(SRCS)
|
||||
$(SWIG) -python $(SWIGOPT) $(INTERFACE)
|
||||
$(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDE) $(PYTHON_INCLUDE)
|
||||
$(LDSHARED) $(OBJS) $(IOBJS) $(LIBS) -o $(TARGET)module$(SO)
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
# Build a C++ dynamically loadable module
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
python_cpp: $(SRCS)
|
||||
$(SWIG) -c++ -python $(SWIGOPT) $(INTERFACE)
|
||||
$(CXX) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDE) $(PYTHON_INCLUDE)
|
||||
$(CXXSHARED) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(TARGET)module$(SO)
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
# Build statically linked Python interpreter
|
||||
#
|
||||
# These should only be used in conjunction with the %include embed.i
|
||||
# library file
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
#TKINTER = -L/usr/X11R6.3/lib -L/usr/local/compat/lib -ltk4.0 -ltcl7.4 -lX11
|
||||
TKINTER =
|
||||
PYTHON_LIBOPTS = @PYLINK@ @LIBS@ $(TKINTER) $(SYSLIBS)
|
||||
|
||||
python_static: $(SRCS)
|
||||
$(SWIG) -python -lembed.i $(SWIGOPT) $(INTERFACE)
|
||||
$(CC) $(CFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCS) $(INCLUDE) \
|
||||
$(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET)
|
||||
|
||||
python_static_cpp: $(SRCS)
|
||||
$(SWIG) -c++ -python -lembed.i $(SWIGOPT) $(INTERFACE)
|
||||
$(CXX) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDE) \
|
||||
$(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET)
|
||||
|
||||
|
||||
##################################################################
|
||||
##### SWIG ######
|
||||
##################################################################
|
||||
|
||||
# Build a new SWIG extension
|
||||
|
||||
SWIGINCLUDE = -I${prefix}/include
|
||||
SWIGLIB = -L${exec_prefix}/lib
|
||||
|
||||
swig: $(SRCS)
|
||||
$(CXX) $(SRCS) $(SWIGINCLUDE) $(INCLUDE) $(SWIGLIB) $(LIBS) -lswig -o $(TARGET)
|
||||
|
||||
17
SWIG/Examples/perl5/simple/Makefile
Normal file
17
SWIG/Examples/perl5/simple/Makefile
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
SWIGOPT =
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.o core *~ *.so *.pm myperl
|
||||
|
||||
1
SWIG/Examples/perl5/simple/README
Normal file
1
SWIG/Examples/perl5/simple/README
Normal file
|
|
@ -0,0 +1 @@
|
|||
Simple example from users manual.
|
||||
24
SWIG/Examples/perl5/simple/example.c
Normal file
24
SWIG/Examples/perl5/simple/example.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* Simple example from documentation */
|
||||
/* File : example.c */
|
||||
|
||||
#include <time.h>
|
||||
|
||||
double My_variable = 3.0;
|
||||
|
||||
/* Compute factorial of n */
|
||||
int fact(int n) {
|
||||
if (n <= 1) return 1;
|
||||
else return n*fact(n-1);
|
||||
}
|
||||
|
||||
/* Compute n mod m */
|
||||
int my_mod(int n, int m) {
|
||||
return (n % m);
|
||||
}
|
||||
|
||||
|
||||
char *get_time() {
|
||||
long ltime;
|
||||
time(<ime);
|
||||
return ctime(<ime);
|
||||
}
|
||||
11
SWIG/Examples/perl5/simple/example.i
Normal file
11
SWIG/Examples/perl5/simple/example.i
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%{
|
||||
/* Put headers and other declarations here */
|
||||
%}
|
||||
|
||||
|
||||
extern double My_variable;
|
||||
extern int fact(int);
|
||||
%name(mod) extern int my_mod(int n, int m);
|
||||
extern char *get_time();
|
||||
23
SWIG/Examples/perl5/simple/example.pl
Executable file
23
SWIG/Examples/perl5/simple/example.pl
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# Perl5 script for testing simple example
|
||||
|
||||
use example;
|
||||
package example;
|
||||
|
||||
print get_time();
|
||||
print "My Variable = $My_variable","\n";
|
||||
for ($i = 0; $i < 14; $i++) {
|
||||
$n = fact($i);
|
||||
print "$i factorial is $n\n";
|
||||
}
|
||||
|
||||
for ($i = 1; $i < 250; $i++) {
|
||||
for ($j = 1; $j < 250; $j++) {
|
||||
$n = mod($i,$j);
|
||||
$My_variable = $My_variable + $n;
|
||||
}
|
||||
}
|
||||
|
||||
print "My_variable = ", $My_variable, "\n";
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
28
SWIG/Examples/tcl/simple/Makefile
Normal file
28
SWIG/Examples/tcl/simple/Makefile
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SRCS = example.c
|
||||
TARGET = my_tclsh
|
||||
DLTARGET = example
|
||||
INTERFACE = example.i
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcldl
|
||||
|
||||
tcl8::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='-tcl8' TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcldl
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh
|
||||
|
||||
static8::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='-tcl8' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh
|
||||
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.o my_tclsh *~ .~* core *.so *.sl
|
||||
|
||||
|
||||
10
SWIG/Examples/tcl/simple/README
Normal file
10
SWIG/Examples/tcl/simple/README
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
This is a simple Tcl example. Type 'make' to
|
||||
compile a dynamically loadable extension.
|
||||
|
||||
'make tcl8' creates a dynamically loadable Tcl 8.x
|
||||
extension.
|
||||
|
||||
'make static' creates a statically linked 'tclsh' executable.
|
||||
|
||||
'make static8' create a statically linked 'tclsh8.0' executable.
|
||||
|
||||
25
SWIG/Examples/tcl/simple/example.c
Normal file
25
SWIG/Examples/tcl/simple/example.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* Simple example from documentation */
|
||||
/* File : example.c */
|
||||
|
||||
#ifdef SWIG
|
||||
%module example
|
||||
#endif
|
||||
|
||||
#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);
|
||||
}
|
||||
21
SWIG/Examples/tcl/simple/example.i
Normal file
21
SWIG/Examples/tcl/simple/example.i
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%{
|
||||
/* Put headers and other declarations here */
|
||||
|
||||
char foo[] = "Help me!";
|
||||
%}
|
||||
|
||||
typedef double * DoublePtr;
|
||||
typedef double Real;
|
||||
|
||||
typedef Vector * Foo;
|
||||
|
||||
extern double My_variable;
|
||||
extern int fact(int);
|
||||
extern int mod(int n, int m);
|
||||
extern char *get_time();
|
||||
char foo[];
|
||||
|
||||
|
||||
|
||||
26
SWIG/Examples/tcl/simple/example.tcl
Normal file
26
SWIG/Examples/tcl/simple/example.tcl
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# Tcl script for testing simple example
|
||||
|
||||
# Try to load as a dynamic module. If not, we'll just assume
|
||||
# that it was statically linked in.
|
||||
|
||||
catch { load ./example.so example}
|
||||
catch { load ./example.dll example} ;# Windows
|
||||
|
||||
puts [get_time]
|
||||
set tcl_precision 17
|
||||
puts "My Variable = $My_variable"
|
||||
for {set i 0} {$i < 14} {incr i 1} {
|
||||
set n [fact $i];
|
||||
puts "$i factorial is $n"
|
||||
}
|
||||
|
||||
for {set i 1} {$i < 250} {incr i 1} {
|
||||
for {set j 1} {$j < 250} {incr j 1} {
|
||||
set n [mod $i $j]
|
||||
set My_variable [expr {$My_variable + $n}]
|
||||
}
|
||||
}
|
||||
|
||||
puts "My_variable = $My_variable"
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue