Initial revision

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@392 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Thien-Thi Nguyen 2000-04-06 08:26:59 +00:00
commit 8d704fbc0f
10 changed files with 1941 additions and 0 deletions

View 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

View file

@ -0,0 +1 @@
Simple example from users manual.

View 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(&ltime);
return ctime(&ltime);
}

View 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();

View 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))