Initial revision
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@392 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
eff632b744
commit
8d704fbc0f
10 changed files with 1941 additions and 0 deletions
12
SWIG/Examples/mzscheme/simple/Makefile
Normal file
12
SWIG/Examples/mzscheme/simple/Makefile
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
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)' mzscheme
|
||||
clean::
|
||||
rm -f *_wrap* *.o core *~ *.so
|
||||
|
||||
1
SWIG/Examples/mzscheme/simple/README
Normal file
1
SWIG/Examples/mzscheme/simple/README
Normal file
|
|
@ -0,0 +1 @@
|
|||
Simple example from users manual.
|
||||
24
SWIG/Examples/mzscheme/simple/example.c
Normal file
24
SWIG/Examples/mzscheme/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);
|
||||
}
|
||||
13
SWIG/Examples/mzscheme/simple/example.i
Normal file
13
SWIG/Examples/mzscheme/simple/example.i
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%{
|
||||
/* Put headers and other declarations here */
|
||||
%}
|
||||
|
||||
%include typemaps.i
|
||||
|
||||
extern double My_variable;
|
||||
extern int fact(int);
|
||||
%name(mod) extern int my_mod(int n, int m);
|
||||
extern int my_mod(int n, int m);
|
||||
extern char *get_time();
|
||||
24
SWIG/Examples/mzscheme/simple/example.scm
Normal file
24
SWIG/Examples/mzscheme/simple/example.scm
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
;; run with mzscheme -r example.scm
|
||||
|
||||
(load-extension "example.so")
|
||||
|
||||
(display (get-time))
|
||||
|
||||
(printf "My-variable = ~a~n" (my-variable))
|
||||
|
||||
(let loop ((i 0))
|
||||
(when (< i 14) (begin (display i)
|
||||
(display " factorial is ")
|
||||
(display (fact i))
|
||||
(newline)
|
||||
(loop (+ i 1)))))
|
||||
|
||||
(let loop ((i 1))
|
||||
(when (< i 250)
|
||||
(begin
|
||||
(let loopi ((j 1))
|
||||
(when (< j 250) (begin (my-variable (+ (my-variable) (mod i j)))
|
||||
(loopi (+ j 1)))))
|
||||
(loop (+ i 1)))))
|
||||
|
||||
(printf "My-variable = ~a~n" (my-variable))
|
||||
Loading…
Add table
Add a link
Reference in a new issue