diff options
author | Dave Beazley <dave-swig@dabeaz.com> | 2000-01-12 03:21:25 +0000 |
---|---|---|
committer | Dave Beazley <dave-swig@dabeaz.com> | 2000-01-12 03:21:25 +0000 |
commit | 63880a6e34c1c1f8c7e0850fe248f89042c3d22c (patch) | |
tree | 45c9513df85d76b4c46b62beaf60745c1d282150 /Examples/tcl/simple | |
parent | ad3d48ca1527b066d048c980d10f24448a5161a1 (diff) | |
download | swig-63880a6e34c1c1f8c7e0850fe248f89042c3d22c.tar.gz |
*** empty log message ***
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@50 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Examples/tcl/simple')
-rw-r--r-- | Examples/tcl/simple/Makefile | 28 | ||||
-rw-r--r-- | Examples/tcl/simple/README | 10 | ||||
-rw-r--r-- | Examples/tcl/simple/example.c | 25 | ||||
-rw-r--r-- | Examples/tcl/simple/example.i | 21 | ||||
-rw-r--r-- | Examples/tcl/simple/example.tcl | 26 |
5 files changed, 110 insertions, 0 deletions
diff --git a/Examples/tcl/simple/Makefile b/Examples/tcl/simple/Makefile new file mode 100644 index 000000000..afeb32c2f --- /dev/null +++ b/Examples/tcl/simple/Makefile @@ -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 + + diff --git a/Examples/tcl/simple/README b/Examples/tcl/simple/README new file mode 100644 index 000000000..031b17bc5 --- /dev/null +++ b/Examples/tcl/simple/README @@ -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. + diff --git a/Examples/tcl/simple/example.c b/Examples/tcl/simple/example.c new file mode 100644 index 000000000..f132e908b --- /dev/null +++ b/Examples/tcl/simple/example.c @@ -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); +} diff --git a/Examples/tcl/simple/example.i b/Examples/tcl/simple/example.i new file mode 100644 index 000000000..f0c76c1de --- /dev/null +++ b/Examples/tcl/simple/example.i @@ -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[]; + + + diff --git a/Examples/tcl/simple/example.tcl b/Examples/tcl/simple/example.tcl new file mode 100644 index 000000000..3a6683aa7 --- /dev/null +++ b/Examples/tcl/simple/example.tcl @@ -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" + |