Initial revision.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@364 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
0b36fa3b37
commit
2586b50825
5 changed files with 97 additions and 0 deletions
18
SWIG/Examples/guile/simple/Makefile
Normal file
18
SWIG/Examples/guile/simple/Makefile
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
CC = gcc
|
||||||
|
SRCS = example.c
|
||||||
|
TARGET = my-guile
|
||||||
|
IFILE = example.i
|
||||||
|
MKDIR = ..
|
||||||
|
|
||||||
|
all::
|
||||||
|
$(MAKE) -f $(MKDIR)/Makefile \
|
||||||
|
SRCS='$(SRCS)' \
|
||||||
|
TARGET=$(TARGET) \
|
||||||
|
IFILE=$(IFILE) \
|
||||||
|
CC=$(CC) \
|
||||||
|
sub-all
|
||||||
|
|
||||||
|
clean::
|
||||||
|
rm -f *_wrap* my-guile *~ .~* core
|
||||||
|
|
||||||
|
|
||||||
9
SWIG/Examples/guile/simple/README
Normal file
9
SWIG/Examples/guile/simple/README
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
A very simple example.
|
||||||
|
|
||||||
|
To run it, start the program 'my-guile' and type:
|
||||||
|
|
||||||
|
(load 'example.scm)
|
||||||
|
|
||||||
|
Alternatively, you can use the shell command:
|
||||||
|
|
||||||
|
./my-guile -s example.scm
|
||||||
21
SWIG/Examples/guile/simple/example.c
Normal file
21
SWIG/Examples/guile/simple/example.c
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
/* Simple example from documentation */
|
||||||
|
/* File : example.c */
|
||||||
|
|
||||||
|
#include </usr/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);
|
||||||
|
}
|
||||||
14
SWIG/Examples/guile/simple/example.i
Normal file
14
SWIG/Examples/guile/simple/example.i
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
/* File : example.i */
|
||||||
|
%module Example
|
||||||
|
%{
|
||||||
|
/* Put headers and other declarations here */
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include guile/typemaps.i
|
||||||
|
|
||||||
|
extern double My_variable;
|
||||||
|
extern int fact(int);
|
||||||
|
extern int mod(int n, int m);
|
||||||
|
extern char *get_time();
|
||||||
|
|
||||||
|
%include guile/guilemain.i
|
||||||
35
SWIG/Examples/guile/simple/example.scm
Normal file
35
SWIG/Examples/guile/simple/example.scm
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
;;;
|
||||||
|
;;; Guile script for simple example.
|
||||||
|
;;; Is a little clumsy since I'm not the greatest scheme programmer.
|
||||||
|
;;;
|
||||||
|
|
||||||
|
(display (get-time))
|
||||||
|
(display "My variable = ")
|
||||||
|
(display (My-variable))
|
||||||
|
(newline)
|
||||||
|
|
||||||
|
(define (facts x max)
|
||||||
|
(if (< x max)
|
||||||
|
(begin
|
||||||
|
(display (string-append (number->string x) " factorial is "
|
||||||
|
(number->string (fact x))))
|
||||||
|
(newline)
|
||||||
|
(facts (+ x 1) max))))
|
||||||
|
|
||||||
|
(facts 0 14)
|
||||||
|
|
||||||
|
|
||||||
|
(define (mods i imax j jmax)
|
||||||
|
(if (< i imax)
|
||||||
|
(if (< j jmax)
|
||||||
|
(begin
|
||||||
|
(My-variable (+ (My-variable) (mod i j)))
|
||||||
|
(mods i imax (+ j 1) jmax))
|
||||||
|
(mods (+ i 1) imax 1 jmax))))
|
||||||
|
|
||||||
|
(mods 1 250 1 250)
|
||||||
|
|
||||||
|
(display (string-append "My-variable = " (number->string (My-variable))))
|
||||||
|
(newline)
|
||||||
|
|
||||||
|
;;; example.scm ends here
|
||||||
Loading…
Add table
Add a link
Reference in a new issue