Initial addition.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4313 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
870e6457d1
commit
85ace8facd
70 changed files with 9710 additions and 0 deletions
3
SWIG/Examples/GIFPlot/Chicken/check.list
Normal file
3
SWIG/Examples/GIFPlot/Chicken/check.list
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# see top-level Makefile.in
|
||||
full
|
||||
simple
|
||||
3
SWIG/Examples/GIFPlot/Chicken/full/.cvsignore
Normal file
3
SWIG/Examples/GIFPlot/Chicken/full/.cvsignore
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
gifplot-guile
|
||||
gifplot_wrap.c
|
||||
image.gif
|
||||
61
SWIG/Examples/GIFPlot/Chicken/full/Makefile.in
Normal file
61
SWIG/Examples/GIFPlot/Chicken/full/Makefile.in
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
@SET_MAKE@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
SOURCE_DIR = $(top_srcdir)/Examples/GIFPlot/Chicken/full
|
||||
TOP = ../../..
|
||||
CC = @CC@
|
||||
CXX = @CXX@
|
||||
OBJEXT = @OBJEXT@
|
||||
EXEEXT = @EXEEXT@
|
||||
SWIG = $(TOP)/../swig$(EXEEXT)
|
||||
CHICKGEN = gifplot_wrap.$(OBJEXT) csi.$(OBJEXT) precsi.$(OBJEXT) \
|
||||
ogifplot.$(OBJEXT)
|
||||
CHICKSRC = csi.c precsi.c ogifplot.c
|
||||
SRCS = $(CHICKGEN)
|
||||
TARGET = gifplot$(EXEEXT)
|
||||
INCLUDE = -I$(SOURCE_DIR) -I../../Include
|
||||
LIBS = -L../.. -lgifplot -lm
|
||||
SWIGOPT = -I../../Include
|
||||
|
||||
all:: $(TARGET)
|
||||
|
||||
.SUFFIXES: .cxx
|
||||
|
||||
.c.o:
|
||||
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
.cxx.o:
|
||||
$(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
csi.c:
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='csi.c' \
|
||||
INTERFACE='precsi' chicken_csi
|
||||
|
||||
precsi.c: $(SOURCE_DIR)/precsi.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='precsi.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
gifplot_wrap.c gifplot.scm: $(SOURCE_DIR)/gifplot.i
|
||||
(test $< -nt gifplot.i && cp -p $< gifplot.i) || echo gifplot.i is up-to-date
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
INCLUDE='$(INCLUDE)' INTERFACE='gifplot.i' chicken_c
|
||||
|
||||
ogifplot.c: gifplot.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='ogifplot.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
$(TARGET): $(SRCS)
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
|
||||
LIBS='$(LIBS)' INTERFACE='$(INTERFACE)' chicken_static
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.$(OBJEXT) core *~ *.so *.stackdump STACKTRACE
|
||||
rm -f $(CHICKGEN) $(CHICKSRC)
|
||||
rm -f gifplot.scm
|
||||
rm -f $(TARGET)
|
||||
rm -f *.gif
|
||||
|
||||
check: all
|
||||
4
SWIG/Examples/GIFPlot/Chicken/full/README
Normal file
4
SWIG/Examples/GIFPlot/Chicken/full/README
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
This example runs the entire gifplot.h header file through SWIG without
|
||||
any changes. The Scheme program 'test-gifplot.scm' does something a
|
||||
little more interesting. You'll have to go look at the header file to
|
||||
get a complete listing of the functions.
|
||||
BIN
SWIG/Examples/GIFPlot/Chicken/full/cmap
Normal file
BIN
SWIG/Examples/GIFPlot/Chicken/full/cmap
Normal file
Binary file not shown.
26
SWIG/Examples/GIFPlot/Chicken/full/gifplot.i
Normal file
26
SWIG/Examples/GIFPlot/Chicken/full/gifplot.i
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* Oh what the heck, let's just grab the whole darn header file
|
||||
and see what happens. */
|
||||
|
||||
%module gifplot
|
||||
%{
|
||||
|
||||
/* Note: You still need this part because the %include directive
|
||||
merely causes SWIG to interpret the contents of a file. It doesn't
|
||||
include the right include headers for the resulting C code */
|
||||
|
||||
#include "gifplot.h"
|
||||
|
||||
%}
|
||||
|
||||
/* Pixel is typedef'd to unsigned char, and SWIG will translate this
|
||||
type into Scheme characters. We would like to translate Pixels to
|
||||
Scheme integers instead, so: */
|
||||
|
||||
SIMPLE_TYPEMAP(Pixel, C_unfix, C_fix, C_swig_is_fixnum, (int), 0);
|
||||
|
||||
%{
|
||||
static Pixel int_to_Pixel (int v) { return (Pixel) v; }
|
||||
%}
|
||||
extern Pixel int_to_Pixel (int v);
|
||||
|
||||
%include gifplot.h
|
||||
8
SWIG/Examples/GIFPlot/Chicken/full/precsi.scm
Normal file
8
SWIG/Examples/GIFPlot/Chicken/full/precsi.scm
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(declare (unit precsi))
|
||||
(declare (uses gifplot))
|
||||
|
||||
;; display prelude to csi
|
||||
(display "full\n\n")
|
||||
|
||||
(display " A SWIG GIFPlot example for the CHICKEN compiler\n")
|
||||
(display " Author: Jonah Beckford, December 2002\n\n")
|
||||
64
SWIG/Examples/GIFPlot/Chicken/full/test-gifplot.scm
Normal file
64
SWIG/Examples/GIFPlot/Chicken/full/test-gifplot.scm
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
;;; Plot a 3D function
|
||||
|
||||
;; Here is the function to plot
|
||||
(define (func x y)
|
||||
(* 5
|
||||
(cos (* 2 (sqrt (+ (* x x) (* y y)))))
|
||||
(exp (* -0.3 (sqrt (+ (* x x) (* y y)))))))
|
||||
|
||||
;; Here are some plotting parameters
|
||||
(define xmin -5.0)
|
||||
(define xmax 5.0)
|
||||
(define ymin -5.0)
|
||||
(define ymax 5.0)
|
||||
(define zmin -5.0)
|
||||
(define zmax 5.0)
|
||||
|
||||
;; Grid resolution
|
||||
(define nxpoints 60)
|
||||
(define nypoints 60)
|
||||
|
||||
(define cmap (gifplot-new-ColorMap "cmap"))
|
||||
(define frame (gifplot-new-FrameBuffer 500 500))
|
||||
(gifplot-FrameBuffer-clear frame (gifplot-BLACK))
|
||||
|
||||
(define p3 (gifplot-new-Plot3D frame xmin ymin zmin xmax ymax zmax))
|
||||
(gifplot-Plot3D-lookat p3 (* 2 (- zmax zmin)))
|
||||
(gifplot-Plot3D-autoperspective p3 40.0)
|
||||
(gifplot-Plot3D-rotu p3 60.0)
|
||||
(gifplot-Plot3D-rotr p3 30.0)
|
||||
(gifplot-Plot3D-rotd p3 10.0)
|
||||
|
||||
(define (drawsolid)
|
||||
(gifplot-Plot3D-clear p3 (gifplot-BLACK))
|
||||
(gifplot-Plot3D-start p3)
|
||||
(let ((dx (/ (- xmax xmin) nxpoints))
|
||||
(dy (/ (- ymax ymin) nypoints))
|
||||
(cscale (/ 240 (- zmax zmin))))
|
||||
(let x-loop ((x xmin) (i 0))
|
||||
(cond
|
||||
((< i nxpoints)
|
||||
(let y-loop ((y ymin) (j 0))
|
||||
(cond
|
||||
((< j nypoints)
|
||||
(let* ((z1 (func x y))
|
||||
(z2 (func (+ x dx) y))
|
||||
(z3 (func (+ x dx) (+ y dy)))
|
||||
(z4 (func x (+ y dy)))
|
||||
(c1 (* cscale (- z1 zmin)))
|
||||
(c2 (* cscale (- z2 zmin)))
|
||||
(c3 (* cscale (- z3 zmin)))
|
||||
(c4 (* cscale (- z4 zmin)))
|
||||
(cc (/ (+ c1 c2 c3 c4) 4))
|
||||
(c (inexact->exact (round (max (min cc 239) 0)))))
|
||||
(gifplot-Plot3D-solidquad p3 x y z1 (+ x dx) y z2 (+ x dx) (+ y dy)
|
||||
z3 x (+ y dy) z4
|
||||
(gifplot-int->Pixel (+ c 16))))
|
||||
(y-loop (+ y dy) (+ j 1)))))
|
||||
(x-loop (+ x dx) (+ i 1)))))))
|
||||
|
||||
(display "Making a nice 3D plot...\n")
|
||||
(drawsolid)
|
||||
|
||||
(gifplot-FrameBuffer-writeGIF frame cmap "image.gif")
|
||||
(display "Wrote image.gif\n")
|
||||
4
SWIG/Examples/GIFPlot/Chicken/simple/.cvsignore
Normal file
4
SWIG/Examples/GIFPlot/Chicken/simple/.cvsignore
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
gifguile
|
||||
image.gif
|
||||
simple-guile
|
||||
simple_wrap.c
|
||||
61
SWIG/Examples/GIFPlot/Chicken/simple/Makefile.in
Normal file
61
SWIG/Examples/GIFPlot/Chicken/simple/Makefile.in
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
@SET_MAKE@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
SOURCE_DIR = $(top_srcdir)/Examples/GIFPlot/Chicken/simple
|
||||
TOP = ../../..
|
||||
CC = @CC@
|
||||
CXX = @CXX@
|
||||
OBJEXT = @OBJEXT@
|
||||
EXEEXT = @EXEEXT@
|
||||
SWIG = $(TOP)/../swig$(EXEEXT)
|
||||
CHICKGEN = simple_wrap.$(OBJEXT) csi.$(OBJEXT) precsi.$(OBJEXT) \
|
||||
osimple.$(OBJEXT)
|
||||
CHICKSRC = csi.c precsi.c osimple.c
|
||||
SRCS = $(CHICKGEN)
|
||||
TARGET = simple$(EXEEXT)
|
||||
INCLUDE = -I$(SOURCE_DIR) -I../../Include
|
||||
LIBS = -L../.. -lgifplot -lm
|
||||
SWIGOPT = -I../../Include
|
||||
|
||||
all:: $(TARGET)
|
||||
|
||||
.SUFFIXES: .cxx
|
||||
|
||||
.c.o:
|
||||
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
.cxx.o:
|
||||
$(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
csi.c:
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='csi.c' \
|
||||
INTERFACE='precsi' chicken_csi
|
||||
|
||||
precsi.c: $(SOURCE_DIR)/precsi.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='precsi.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
simple_wrap.c simple.scm: $(SOURCE_DIR)/simple.i
|
||||
(test $< -nt simple.i && cp -p $< simple.i) || echo simple.i is up-to-date
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
INCLUDE='$(INCLUDE)' INTERFACE='simple.i' chicken_c
|
||||
|
||||
osimple.c: simple.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='osimple.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
$(TARGET): $(SRCS)
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
|
||||
LIBS='$(LIBS)' INTERFACE='$(INTERFACE)' chicken_static
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.$(OBJEXT) core *~ *.so *.stackdump STACKTRACE
|
||||
rm -f $(CHICKGEN) $(CHICKSRC)
|
||||
rm -f simple.scm
|
||||
rm -f $(TARGET)
|
||||
rm -f *.gif
|
||||
|
||||
check: all
|
||||
6
SWIG/Examples/GIFPlot/Chicken/simple/README
Normal file
6
SWIG/Examples/GIFPlot/Chicken/simple/README
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
This is a very minimalistic example in which just a few functions
|
||||
and constants from library are wrapped and used to draw some simple
|
||||
shapes.
|
||||
|
||||
`make' will build a version of CHICKEN which defines an additional
|
||||
unit (simple). Run `./simple runme.scm' to test it.
|
||||
33
SWIG/Examples/GIFPlot/Chicken/simple/STACKTRACE
Normal file
33
SWIG/Examples/GIFPlot/Chicken/simple/STACKTRACE
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
...more...
|
||||
/usr/local/share/chicken/src/csi.scm: 887 string-split
|
||||
##sys#map
|
||||
/usr/local/share/chicken/src/csi.scm: 914 load-verbose
|
||||
/usr/local/share/chicken/src/csi.scm: 915 ##csi#print-banner
|
||||
/usr/local/share/chicken/src/csi.scm: 113 printf
|
||||
/usr/local/share/chicken/src/csi.scm: 920 collect-options
|
||||
##sys#for-each
|
||||
/usr/local/share/chicken/src/csi.scm: 921 collect-options
|
||||
##sys#for-each
|
||||
/usr/local/share/chicken/src/csi.scm: 924 collect-options
|
||||
##sys#map
|
||||
/usr/local/share/chicken/src/csi.scm: 924 append
|
||||
/usr/local/share/chicken/src/csi.scm: 923 delete-duplicates
|
||||
/usr/local/share/chicken/src/csi.scm: 929 provide
|
||||
/usr/local/share/chicken/src/csi.scm: 899 getenv
|
||||
/usr/local/share/chicken/src/csi.scm: 899 ##csi#chop-separator
|
||||
/usr/local/share/chicken/src/csi.scm: 138 sub1
|
||||
/usr/local/share/chicken/src/csi.scm: 900 string
|
||||
/usr/local/share/chicken/src/csi.scm: 900 string-append
|
||||
/usr/local/share/chicken/src/csi.scm: 901 file-exists?
|
||||
/usr/local/share/chicken/src/csi.scm: 959 ##csi#make-transcript-port
|
||||
/usr/local/share/chicken/src/csi.scm: 360 ##sys#make-port
|
||||
/usr/local/share/chicken/src/csi.scm: 984 substring
|
||||
/usr/local/share/chicken/src/csi.scm: 991 load
|
||||
/usr/local/share/chicken/src/csi.scm: 381 ##sys#print
|
||||
/usr/local/share/chicken/src/csi.scm: 381 ##sys#print
|
||||
/usr/local/share/chicken/src/csi.scm: 381 ##sys#print
|
||||
/usr/local/share/chicken/src/csi.scm: 381 ##sys#print
|
||||
/usr/local/share/chicken/src/csi.scm: 129 old-hook
|
||||
new-ColorMap
|
||||
new-FrameBuffer
|
||||
BLACK
|
||||
8
SWIG/Examples/GIFPlot/Chicken/simple/precsi.scm
Normal file
8
SWIG/Examples/GIFPlot/Chicken/simple/precsi.scm
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(declare (unit precsi))
|
||||
(declare (uses simple))
|
||||
|
||||
;; display prelude to csi
|
||||
(display "simple\n\n")
|
||||
|
||||
(display " A SWIG GIFPlot example for the CHICKEN compiler\n")
|
||||
(display " Author: Jonah Beckford, December 2002\n\n")
|
||||
34
SWIG/Examples/GIFPlot/Chicken/simple/simple.i
Normal file
34
SWIG/Examples/GIFPlot/Chicken/simple/simple.i
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* This example shows a very simple interface wrapping a few
|
||||
primitive declarations */
|
||||
|
||||
%module simple
|
||||
%{
|
||||
#include "gifplot.h"
|
||||
%}
|
||||
|
||||
typedef unsigned int Pixel;
|
||||
|
||||
/* Here are a few useful functions */
|
||||
|
||||
ColorMap *new_ColorMap(char *filename = 0);
|
||||
void delete_ColorMap(ColorMap *cmap);
|
||||
|
||||
FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height);
|
||||
void delete_FrameBuffer(FrameBuffer *frame);
|
||||
void FrameBuffer_clear(FrameBuffer *frame, Pixel color);
|
||||
void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color);
|
||||
void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color);
|
||||
void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color);
|
||||
int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename);
|
||||
|
||||
/* And some useful constants, which we redefine (from gifplot.h) so
|
||||
that SWIG sees them */
|
||||
#define BLACK 0
|
||||
#define WHITE 1
|
||||
#define RED 2
|
||||
#define GREEN 3
|
||||
#define BLUE 4
|
||||
#define YELLOW 5
|
||||
#define CYAN 6
|
||||
#define MAGENTA 7
|
||||
|
||||
49
SWIG/Examples/GIFPlot/Chicken/simple/simple.scm
Normal file
49
SWIG/Examples/GIFPlot/Chicken/simple/simple.scm
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
;; -*- buffer-read-only: t -*- vi: set ro:
|
||||
;; This file was created automatically by SWIG.
|
||||
;; Don't modify this file, modify the SWIG interface instead.
|
||||
(cond-expand ((or chicken-compile-shared shared)) (else (declare (unit simple))))
|
||||
|
||||
(declare
|
||||
(hide swig-init)
|
||||
(foreign-declare "C_extern void simple_swig_init(int,C_word,C_word) C_noret;"))
|
||||
(define swig-init (##core#primitive "simple_swig_init"))
|
||||
(swig-init)
|
||||
|
||||
|
||||
(declare
|
||||
(foreign-declare "C_extern int simple_swig_num_types (void);")
|
||||
(foreign-declare "C_extern char* simple_swig_type_name (int);")
|
||||
(foreign-declare "C_extern void* simple_swig_type_ptr (int);")
|
||||
(foreign-declare "C_extern char* simple_swig_type_str (int);")
|
||||
(foreign-declare "C_extern void simple_swig_type_tag (int, C_word);"))
|
||||
(define-record swig-simple-tag class name ptr str)
|
||||
(define-record-printer (swig-simple-tag tag out)
|
||||
(fprintf out "#<tag ~S>(~A)" (swig-simple-tag-str tag)
|
||||
(swig-simple-tag-ptr tag)))
|
||||
(define swig-simple-tag-num
|
||||
((foreign-lambda int "simple_swig_num_types")))
|
||||
(define swig-simple-tags (make-vector swig-simple-tag-num #f))
|
||||
(letrec
|
||||
((gen
|
||||
(lambda (l i)
|
||||
(if (= i 0) (cons 0 l) (gen (cons i l) (- i 1))))))
|
||||
(let ((indices (if (<= swig-simple-tag-num 0) (quote ())
|
||||
(gen (quote ()) (- swig-simple-tag-num 1)))))
|
||||
(for-each
|
||||
(lambda (index)
|
||||
(let
|
||||
((tag
|
||||
(make-swig-simple-tag
|
||||
1000
|
||||
((foreign-lambda
|
||||
c-string "simple_swig_type_name" int) index)
|
||||
((foreign-lambda
|
||||
c-pointer "simple_swig_type_ptr" int) index)
|
||||
((foreign-lambda
|
||||
c-string "simple_swig_type_str" int) index))))
|
||||
(vector-set! swig-simple-tags index tag)
|
||||
((foreign-lambda void "simple_swig_type_tag"
|
||||
int scheme-object) index tag)))
|
||||
indices)))
|
||||
|
||||
|
||||
27
SWIG/Examples/GIFPlot/Chicken/simple/test-simple.scm
Normal file
27
SWIG/Examples/GIFPlot/Chicken/simple/test-simple.scm
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
;;; Draw some simple shapes
|
||||
|
||||
(display "Drawing some basic shapes\n")
|
||||
|
||||
(define cmap (simple-new-ColorMap #f))
|
||||
(define f (simple-new-FrameBuffer 400 400))
|
||||
|
||||
;; Clear the picture
|
||||
(simple-FrameBuffer-clear f (simple-BLACK))
|
||||
|
||||
;; Make a red box
|
||||
(simple-FrameBuffer-box f 40 40 200 200 (simple-RED))
|
||||
|
||||
;; Make a blue circle
|
||||
(simple-FrameBuffer-circle f 200 200 40 (simple-BLUE))
|
||||
|
||||
;; Make green line
|
||||
(simple-FrameBuffer-line f 10 390 390 200 (simple-GREEN))
|
||||
|
||||
;; Write an image out to disk
|
||||
|
||||
(simple-FrameBuffer-writeGIF f cmap "image.gif")
|
||||
(display "Wrote image.gif\n")
|
||||
|
||||
(simple-delete-FrameBuffer f)
|
||||
(simple-delete-ColorMap cmap)
|
||||
|
||||
15
SWIG/Examples/chicken/README
Normal file
15
SWIG/Examples/chicken/README
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
This directory contains examples for CHICKEN.
|
||||
|
||||
class -- illustrates the shadow-class C++ interface
|
||||
constants -- handling #define and %constant literals
|
||||
multimap -- typemaps with multiple sub-types
|
||||
overload -- C++ function overloading
|
||||
simple -- the simple example from the user manual
|
||||
vtk -- a full-blown wrapping of the Visualization Toolkit
|
||||
|
||||
Note that the examples in this directory build a special version of
|
||||
CHICKEN which includes the wrapped functions in the top-level module.
|
||||
|
||||
If you want to put the wrapped functions into your own module,
|
||||
statically or dynamically linked, see the Examples/GIFPlot/Chicken
|
||||
directory.
|
||||
5
SWIG/Examples/chicken/check.list
Normal file
5
SWIG/Examples/chicken/check.list
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# see top-level Makefile.in
|
||||
class
|
||||
constants
|
||||
multimap
|
||||
simple
|
||||
9
SWIG/Examples/chicken/class/.cvsignore
Normal file
9
SWIG/Examples/chicken/class/.cvsignore
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
*.dll
|
||||
*.dsw
|
||||
*.ncb
|
||||
*.opt
|
||||
*.plg
|
||||
Release
|
||||
Debug
|
||||
59
SWIG/Examples/chicken/class/Makefile.in
Normal file
59
SWIG/Examples/chicken/class/Makefile.in
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
@SET_MAKE@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
SOURCE_DIR = $(top_srcdir)/Examples/chicken/class
|
||||
TOP = ../..
|
||||
CC = @CC@
|
||||
CXX = @CXX@
|
||||
OBJEXT = @OBJEXT@
|
||||
EXEEXT = @EXEEXT@
|
||||
SWIG = $(TOP)/../swig$(EXEEXT)
|
||||
CHICKGEN = example_wrap.$(OBJEXT) csi.$(OBJEXT) precsi.$(OBJEXT) \
|
||||
oexample.$(OBJEXT)
|
||||
CHICKSRC = csi.c precsi.c oexample.c
|
||||
SRCS = $(CHICKGEN) $(SOURCE_DIR)/example.cxx
|
||||
TARGET = class$(EXEEXT)
|
||||
INCLUDE = -I$(SOURCE_DIR)
|
||||
SWIGOPT =
|
||||
|
||||
all:: $(TARGET) example_generic.scm example_clos.scm
|
||||
|
||||
.SUFFIXES: .cxx
|
||||
|
||||
.c.o:
|
||||
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
.cxx.o:
|
||||
$(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
csi.c:
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='csi.c' \
|
||||
INTERFACE='precsi' chicken_csi
|
||||
|
||||
precsi.c: $(SOURCE_DIR)/precsi.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='precsi.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
example_wrap.cxx example.scm example_generic.scm example_clos.scm: $(SOURCE_DIR)/example.i
|
||||
(test $< -nt example.i && cp -p $< example.i) || echo example.i is up-to-date
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
INCLUDE='$(INCLUDE)' INTERFACE='example.i' chicken_cpp
|
||||
|
||||
oexample.c: example.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='oexample.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
$(TARGET): $(SRCS)
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
|
||||
INTERFACE='$(INTERFACE)' chicken_cpp_static
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.$(OBJEXT) core *~ *.so *.stackdump STACKTRACE
|
||||
rm -f $(CHICKGEN) $(CHICKSRC)
|
||||
rm -f example.scm example_generic.scm example_clos.scm
|
||||
rm -f $(TARGET)
|
||||
|
||||
check: all
|
||||
28
SWIG/Examples/chicken/class/example.cxx
Normal file
28
SWIG/Examples/chicken/class/example.cxx
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* File : example.c */
|
||||
|
||||
#include "example.h"
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
/* Move the shape to a new location */
|
||||
void Shape::move(double dx, double dy) {
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
|
||||
int Shape::nshapes = 0;
|
||||
|
||||
double Circle::area(void) {
|
||||
return M_PI*radius*radius;
|
||||
}
|
||||
|
||||
double Circle::perimeter(void) {
|
||||
return 2*M_PI*radius;
|
||||
}
|
||||
|
||||
double Square::area(void) {
|
||||
return width*width;
|
||||
}
|
||||
|
||||
double Square::perimeter(void) {
|
||||
return 4*width;
|
||||
}
|
||||
46
SWIG/Examples/chicken/class/example.h
Normal file
46
SWIG/Examples/chicken/class/example.h
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/* File : example.h */
|
||||
|
||||
class Shape {
|
||||
public:
|
||||
Shape() {
|
||||
nshapes++;
|
||||
}
|
||||
virtual ~Shape() {
|
||||
nshapes--;
|
||||
};
|
||||
double x, y;
|
||||
void move(double dx, double dy);
|
||||
virtual double area(void) = 0;
|
||||
virtual double perimeter(void) = 0;
|
||||
static int nshapes;
|
||||
|
||||
enum SomeEnum {
|
||||
First = 0,
|
||||
Second,
|
||||
Third,
|
||||
Last = 1000
|
||||
};
|
||||
};
|
||||
|
||||
class Circle : public Shape {
|
||||
private:
|
||||
double radius;
|
||||
public:
|
||||
Circle(double r) : radius(r) { };
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
};
|
||||
|
||||
class Square : public Shape {
|
||||
private:
|
||||
double width;
|
||||
public:
|
||||
Square(double w) : width(w) { };
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
16
SWIG/Examples/chicken/class/example.i
Normal file
16
SWIG/Examples/chicken/class/example.i
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* Let "Shape" objects be converted back and forth from TinyCLOS into
|
||||
low-level CHICKEN SWIG procedures */
|
||||
|
||||
%typemap(clos_in) Shape * = SIMPLE_CLOS_OBJECT *;
|
||||
%typemap(clos_out) Shape * = SIMPLE_CLOS_OBJECT *;
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
105
SWIG/Examples/chicken/class/precsi.scm
Normal file
105
SWIG/Examples/chicken/class/precsi.scm
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
(declare (unit precsi))
|
||||
(declare (uses example))
|
||||
|
||||
(if (not (member "-quiet" (cdr (argv))))
|
||||
(begin
|
||||
;; display prelude to csi
|
||||
(display "class\n\n")
|
||||
|
||||
(display " A SWIG example for the CHICKEN compiler\n")
|
||||
(display " Author: Jonah Beckford, December 2002\n\n")
|
||||
|
||||
(display "C++ Interface\n")
|
||||
(display "-------------\n")
|
||||
(display "
|
||||
class Shape {
|
||||
public:
|
||||
Shape();
|
||||
virtual ~Shape();
|
||||
double x, y;
|
||||
void move(double dx, double dy);
|
||||
virtual double area(void) = 0;
|
||||
virtual double perimeter(void) = 0;
|
||||
static int nshapes;
|
||||
enum SomeEnum {
|
||||
First = 0,
|
||||
Second,
|
||||
Third,
|
||||
Last = 1000
|
||||
};
|
||||
};
|
||||
|
||||
class Circle : public Shape {
|
||||
private:
|
||||
double radius;
|
||||
public:
|
||||
Circle(double r);
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
};
|
||||
|
||||
class Square : public Shape {
|
||||
private:
|
||||
double width;
|
||||
public:
|
||||
Square(double w);
|
||||
virtual double area(void);
|
||||
virtual double perimeter(void);
|
||||
};
|
||||
")
|
||||
|
||||
(display "\n")
|
||||
|
||||
(display "CHICKEN Low-Level Procedures\n")
|
||||
(display "----------------------------\n")
|
||||
(display "
|
||||
(define A-CIRCLE-SHAPE (example-new-Circle %radius))
|
||||
(example-Circle-area %circle)
|
||||
(example-Circle-perimeter %circle)
|
||||
(example-delete-Circle %circle)
|
||||
|
||||
(define A-SQUARE-SHAPE (example-new-Square %width))
|
||||
(example-Square-area %square)
|
||||
(example-Square-perimeter %square)
|
||||
(example-delete-Square %square)
|
||||
|
||||
(example-delete-Shape %shape)
|
||||
(example-Shape-x-set %shape %x)
|
||||
(example-Shape-x-get %shape)
|
||||
(example-Shape-y-set %shape %y)
|
||||
(example-Shape-y-get %shape)
|
||||
(example-Shape-move %shape %dx %dy)
|
||||
(example-Shape-area %shape)
|
||||
(example-Shape-perimeter %shape)
|
||||
(example-Shape-nshapes)
|
||||
(example-Shape-nshapes %nshapes-int)
|
||||
(example-Shape-First)
|
||||
(example-Shape-Second)
|
||||
(example-Shape-Third)
|
||||
(example-Shape-Last)
|
||||
")
|
||||
|
||||
(display "\n")
|
||||
|
||||
(display "TinyCLOS Classes\n")
|
||||
(display "----------------\n")
|
||||
(display "
|
||||
;; ALL generic methods must be included first
|
||||
(include \"example_generic\")
|
||||
;; After generic methods are defined, can include TinyCLOS code
|
||||
(include \"example_clos\")
|
||||
|
||||
(define A-CIRCLE-SHAPE (make <example-Circle> %radius))
|
||||
(-get-x- %shapeObject)
|
||||
(-set-x!- %shapeObject %x)
|
||||
(-get-y- %shapeObject)
|
||||
(-set-y!- %shapeObject %y)
|
||||
(-move!- %shapeObject %dx %dy)
|
||||
(-area- %shapeObject)
|
||||
(-perimeter- %shapeObject)
|
||||
(+example-Shape-nshapes+)
|
||||
(+example-Shape-nshapes+ %nshapes-int)
|
||||
;; do not use (example-delete-Shape (slot-ref %shapeObject 'this))
|
||||
;; as %shapeObject is always garbage-collected
|
||||
")
|
||||
(display "\n")))
|
||||
70
SWIG/Examples/chicken/class/test-lowlevel-class.scm
Normal file
70
SWIG/Examples/chicken/class/test-lowlevel-class.scm
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
;; This file illustrates the low-level C++ interface generated
|
||||
;; by SWIG.
|
||||
|
||||
;; ----- Object creation -----
|
||||
|
||||
(display "Creating some objects:\n")
|
||||
(define c (example-new-Circle 10.0))
|
||||
(display " Created circle ")
|
||||
(display c)
|
||||
(display "\n")
|
||||
(define s (example-new-Square 10.0))
|
||||
(display " Created square ")
|
||||
(display s)
|
||||
(display "\n")
|
||||
|
||||
;; ----- Access a static member -----
|
||||
|
||||
(display "\nA total of ")
|
||||
(display (example-Shape-nshapes))
|
||||
(display " shapes were created\n")
|
||||
|
||||
;; ----- Member data access -----
|
||||
|
||||
;; Set the location of the object
|
||||
|
||||
(example-Shape-x-set c 20.0)
|
||||
(example-Shape-y-set c 30.0)
|
||||
|
||||
(example-Shape-x-set s -10.0)
|
||||
(example-Shape-y-set s 5.0)
|
||||
|
||||
(display "\nHere is their current position:\n")
|
||||
(display " Circle = (")
|
||||
(display (example-Shape-x-get c))
|
||||
(display ", ")
|
||||
(display (example-Shape-y-get c))
|
||||
(display ")\n")
|
||||
(display " Square = (")
|
||||
(display (example-Shape-x-get s))
|
||||
(display ", ")
|
||||
(display (example-Shape-y-get s))
|
||||
(display ")\n")
|
||||
|
||||
;; ----- Call some methods -----
|
||||
|
||||
(display "\nHere are some properties of the shapes:\n")
|
||||
(let
|
||||
((disp (lambda (o)
|
||||
(display " ")
|
||||
(display o)
|
||||
(display "\n")
|
||||
(display " area = ")
|
||||
(display (example-Shape-area o))
|
||||
(display "\n")
|
||||
(display " perimeter = ")
|
||||
(display (example-Shape-perimeter o))
|
||||
(display "\n"))))
|
||||
(disp c)
|
||||
(disp s))
|
||||
|
||||
(display "\nGuess I'll clean up now\n")
|
||||
|
||||
;; Note: this invokes the virtual destructor
|
||||
(example-delete-Shape c)
|
||||
(example-delete-Shape s)
|
||||
|
||||
(set! s 3)
|
||||
(display (example-Shape-nshapes))
|
||||
(display " shapes remain\n")
|
||||
(display "Goodbye\n")
|
||||
76
SWIG/Examples/chicken/class/test-tinyclos-class.scm
Normal file
76
SWIG/Examples/chicken/class/test-tinyclos-class.scm
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
;; This file illustrates the shadow C++ interface generated
|
||||
;; by SWIG.
|
||||
|
||||
;; All generic methods must be included first
|
||||
(include "example_generic")
|
||||
|
||||
;; After generic are defined, can include TinyCLOS code
|
||||
(include "example_clos")
|
||||
|
||||
;; ----- Object creation -----
|
||||
|
||||
(display "Creating some objects:\n")
|
||||
(define c (make <example-Circle> 10.0))
|
||||
(display " Created circle ")
|
||||
(display c)
|
||||
(display "\n")
|
||||
(define s (make <example-Square> 10.0))
|
||||
(display " Created square ")
|
||||
(display s)
|
||||
(display "\n")
|
||||
|
||||
;; ----- Access a static member -----
|
||||
|
||||
(display "\nA total of ")
|
||||
(display (+example-Shape-nshapes+))
|
||||
(display " shapes were created\n")
|
||||
|
||||
;; ----- Member data access -----
|
||||
|
||||
;; Set the location of the object
|
||||
|
||||
(-set-x!- c 20.0)
|
||||
(-set-y!- c 30.0)
|
||||
|
||||
(-set-x!- s -10.0)
|
||||
(-set-y!- s 5.0)
|
||||
|
||||
(display "\nHere is their current position:\n")
|
||||
(display " Circle = (")
|
||||
(display (-get-x- c))
|
||||
(display ", ")
|
||||
(display (-get-y- c))
|
||||
(display ")\n")
|
||||
(display " Square = (")
|
||||
(display (-get-x- s))
|
||||
(display ", ")
|
||||
(display (-get-y- s))
|
||||
(display ")\n")
|
||||
|
||||
;; ----- Call some methods -----
|
||||
|
||||
(display "\nHere are some properties of the shapes:\n")
|
||||
(let
|
||||
((disp (lambda (o)
|
||||
(display " ")
|
||||
(display o)
|
||||
(display "\n")
|
||||
(display " area = ")
|
||||
(display (-area- o))
|
||||
(display "\n")
|
||||
(display " perimeter = ")
|
||||
(display (-perimeter- o))
|
||||
(display "\n"))))
|
||||
(disp c)
|
||||
(disp s))
|
||||
|
||||
(display "\nGuess I'll clean up now\n")
|
||||
|
||||
;; Note: Invoke the virtual destructors by forcing garbage collection
|
||||
(set! c 77)
|
||||
(set! s 88)
|
||||
(gc #t)
|
||||
|
||||
(display (+example-Shape-nshapes+))
|
||||
(display " shapes remain\n")
|
||||
(display "Goodbye\n")
|
||||
2
SWIG/Examples/chicken/constants/.cvsignore
Normal file
2
SWIG/Examples/chicken/constants/.cvsignore
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
example_wrap.c
|
||||
my-guile
|
||||
59
SWIG/Examples/chicken/constants/Makefile.in
Normal file
59
SWIG/Examples/chicken/constants/Makefile.in
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
@SET_MAKE@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
SOURCE_DIR = $(top_srcdir)/Examples/chicken/constants
|
||||
TOP = ../..
|
||||
CC = @CC@
|
||||
CXX = @CXX@
|
||||
OBJEXT = @OBJEXT@
|
||||
EXEEXT = @EXEEXT@
|
||||
SWIG = $(TOP)/../swig$(EXEEXT)
|
||||
CHICKGEN = example_wrap.$(OBJEXT) csi.$(OBJEXT) precsi.$(OBJEXT) \
|
||||
oexample.$(OBJEXT)
|
||||
CHICKSRC = csi.c precsi.c oexample.c
|
||||
SRCS = $(CHICKGEN)
|
||||
TARGET = constants$(EXEEXT)
|
||||
INCLUDE = -I$(SOURCE_DIR)
|
||||
SWIGOPT =
|
||||
|
||||
all:: $(TARGET)
|
||||
|
||||
.SUFFIXES: .cxx
|
||||
|
||||
.c.o:
|
||||
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
.cxx.o:
|
||||
$(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
csi.c:
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='csi.c' \
|
||||
INTERFACE='precsi' chicken_csi
|
||||
|
||||
precsi.c: $(SOURCE_DIR)/precsi.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='precsi.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
example_wrap.c example.scm: $(SOURCE_DIR)/example.i
|
||||
(test $< -nt example.i && cp -p $< example.i) || echo example.i is up-to-date
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
INCLUDE='$(INCLUDE)' INTERFACE='example.i' chicken_c
|
||||
|
||||
oexample.c: example.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='oexample.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
$(TARGET): $(SRCS)
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
|
||||
INTERFACE='$(INTERFACE)' chicken_static
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.$(OBJEXT) core *~ *.so *.stackdump STACKTRACE
|
||||
rm -f $(CHICKGEN) $(CHICKSRC)
|
||||
rm -f example.scm
|
||||
rm -f $(TARGET)
|
||||
|
||||
check: all
|
||||
27
SWIG/Examples/chicken/constants/example.i
Normal file
27
SWIG/Examples/chicken/constants/example.i
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
/* A few preprocessor macros */
|
||||
|
||||
#define ICONST 42
|
||||
#define FCONST 2.1828
|
||||
#define CCONST 'x'
|
||||
#define CCONST2 '\n'
|
||||
#define SCONST "Hello World"
|
||||
#define SCONST2 "\"Hello World\""
|
||||
|
||||
/* This should work just fine */
|
||||
#define EXPR ICONST + 3*(FCONST)
|
||||
|
||||
/* This shouldn't do anything */
|
||||
#define EXTERN extern
|
||||
|
||||
/* Neither should this (BAR isn't defined) */
|
||||
#define FOO (ICONST + BAR)
|
||||
|
||||
/* The following directives also produce constants. Remember that
|
||||
CHICKEN is normally case-insensitive, so don't rely on differing
|
||||
case to differentiate variable names */
|
||||
|
||||
%constant int iconstX = 37;
|
||||
%constant double fconstX = 3.14;
|
||||
42
SWIG/Examples/chicken/constants/precsi.scm
Normal file
42
SWIG/Examples/chicken/constants/precsi.scm
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
(declare (unit precsi))
|
||||
(declare (uses example))
|
||||
|
||||
;; display prelude to csi
|
||||
(display "constants\n\n")
|
||||
|
||||
(display " A SWIG example for the CHICKEN compiler\n")
|
||||
(display " Author: Jonah Beckford, December 2002\n\n")
|
||||
|
||||
(display "C Procedures:\n")
|
||||
(display " #define ICONST 42\n")
|
||||
(display " #define FCONST 2.1828\n")
|
||||
(display " #define CCONST 'x'\n")
|
||||
(display " #define CCONST2 '\n'\n")
|
||||
(display " #define SCONST \"Hello World\"\n")
|
||||
(display " #define SCONST2 \"\\\"Hello World\\\"\"\n")
|
||||
(display " /* This should work just fine */\n")
|
||||
(display " #define EXPR ICONST + 3*(FCONST)\n")
|
||||
(display " /* This shouldn't do anything */\n")
|
||||
(display " #define EXTERN extern\n")
|
||||
(display " /* Neither should this (BAR isn't defined) */\n")
|
||||
(display " #define FOO (ICONST + BAR)\n")
|
||||
(display " /* The following directives also produce constants. Remember that\n")
|
||||
(display " CHICKEN is normally case-insensitive, so don't rely on differing\n")
|
||||
(display " case to differentiate variable names */\n")
|
||||
(display " %constant int iconstX = 37;\n")
|
||||
(display " %constant double fconstX = 3.14;\n")
|
||||
(display "\n")
|
||||
|
||||
(display "Scheme Procedures:\n")
|
||||
(display " (example-ICONST)\n")
|
||||
(display " (example-FCONST)\n")
|
||||
(display " (example-CCONST)\n")
|
||||
(display " (example-CCONST2)\n")
|
||||
(display " (example-SCONST)\n")
|
||||
(display " (example-SCONST2)\n")
|
||||
(display " (example-EXPR)\n")
|
||||
(display " (example-EXTERN)\n")
|
||||
(display " (example-FOO)\n")
|
||||
(display " (example-iconstX)\n")
|
||||
(display " (example-fconstX)\n")
|
||||
(display "\n")
|
||||
15
SWIG/Examples/chicken/constants/test-constants.scm
Normal file
15
SWIG/Examples/chicken/constants/test-constants.scm
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
;; run with './constants test-constants.scm'
|
||||
;; feel free to uncomment and comment sections
|
||||
|
||||
(display "starting test ... you will see 'finished' if successful.\n")
|
||||
(or (= (example-ICONST) 42) (exit 1))
|
||||
(or (< (abs (- (example-FCONST) 2.1828)) 0.00001) (exit 1))
|
||||
(or (char=? (example-CCONST) #\x) (exit 1))
|
||||
(or (char=? (example-CCONST2) #\newline) (exit 1))
|
||||
(or (string=? (example-SCONST) "Hello World") (exit 1))
|
||||
(or (string=? (example-SCONST2) "\"Hello World\"") (exit 1))
|
||||
(or (< (abs (- (example-EXPR) (+ (example-ICONST) (* 3 (example-FCONST))))) 0.00001) (exit 1))
|
||||
(or (= (example-iconstX) 37) (exit 1))
|
||||
(or (< (abs (- (example-fconstX) 3.14)) 0.00001) (exit 1))
|
||||
(display "finished test.\n")
|
||||
(exit 0)
|
||||
59
SWIG/Examples/chicken/multimap/Makefile.in
Normal file
59
SWIG/Examples/chicken/multimap/Makefile.in
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
@SET_MAKE@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
SOURCE_DIR = $(top_srcdir)/Examples/chicken/multimap
|
||||
TOP = ../..
|
||||
CC = @CC@
|
||||
CXX = @CXX@
|
||||
OBJEXT = @OBJEXT@
|
||||
EXEEXT = @EXEEXT@
|
||||
SWIG = $(TOP)/../swig$(EXEEXT)
|
||||
CHICKGEN = example_wrap.$(OBJEXT) csi.$(OBJEXT) precsi.$(OBJEXT) \
|
||||
oexample.$(OBJEXT)
|
||||
CHICKSRC = csi.c precsi.c oexample.c
|
||||
SRCS = $(CHICKGEN) $(SOURCE_DIR)/example.c
|
||||
TARGET = multimap$(EXEEXT)
|
||||
INCLUDE = -I$(SOURCE_DIR)
|
||||
SWIGOPT =
|
||||
|
||||
all:: $(TARGET)
|
||||
|
||||
.SUFFIXES: .cxx
|
||||
|
||||
.c.o:
|
||||
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
.cxx.o:
|
||||
$(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
csi.c:
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='csi.c' \
|
||||
INTERFACE='precsi' chicken_csi
|
||||
|
||||
precsi.c: $(SOURCE_DIR)/precsi.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='precsi.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
example_wrap.c example.scm: $(SOURCE_DIR)/example.i
|
||||
(test $< -nt example.i && cp -p $< example.i) || echo example.i is up-to-date
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
INCLUDE='$(INCLUDE)' INTERFACE='example.i' chicken_c
|
||||
|
||||
oexample.c: example.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='oexample.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
$(TARGET): $(SRCS)
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
|
||||
INTERFACE='$(INTERFACE)' chicken_static
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.$(OBJEXT) core *~ *.so *.stackdump STACKTRACE
|
||||
rm -f $(CHICKGEN) $(CHICKSRC)
|
||||
rm -f example.scm
|
||||
rm -f $(TARGET)
|
||||
|
||||
check: all
|
||||
53
SWIG/Examples/chicken/multimap/example.c
Normal file
53
SWIG/Examples/chicken/multimap/example.c
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* File : example.c */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* Compute the greatest common divisor of positive integers */
|
||||
int gcd(int x, int y) {
|
||||
int g;
|
||||
g = y;
|
||||
while (x > 0) {
|
||||
g = x;
|
||||
x = y % x;
|
||||
y = g;
|
||||
}
|
||||
return g;
|
||||
}
|
||||
|
||||
int gcdmain(int argc, char *argv[]) {
|
||||
int x,y;
|
||||
if (argc != 3) {
|
||||
printf("usage: gcd x y\n");
|
||||
return -1;
|
||||
}
|
||||
x = atoi(argv[1]);
|
||||
y = atoi(argv[2]);
|
||||
printf("gcd(%d,%d) = %d\n", x,y,gcd(x,y));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count(char *bytes, int len, char c) {
|
||||
int i;
|
||||
int count = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (bytes[i] == c) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void capitalize(char *str, int len) {
|
||||
int i;
|
||||
for (i = 0; i < len; i++) {
|
||||
str[i] = toupper(str[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void circle(double x, double y) {
|
||||
double a = x*x + y*y;
|
||||
if (a > 1.0) {
|
||||
printf("Bad points %g, %g\n", x,y);
|
||||
} else {
|
||||
printf("Good points %g, %g\n", x,y);
|
||||
}
|
||||
}
|
||||
90
SWIG/Examples/chicken/multimap/example.i
Normal file
90
SWIG/Examples/chicken/multimap/example.i
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%include exception.i
|
||||
%include typemaps.i
|
||||
|
||||
extern int gcd(int x, int y);
|
||||
|
||||
%typemap(chicken,in) (int argc, char *argv[]) {
|
||||
int i;
|
||||
if (!C_swig_is_vector ($input)) {
|
||||
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument $input is not a vector");
|
||||
}
|
||||
$1 = C_header_size ($input);
|
||||
$2 = (char **) malloc(($1+1)*sizeof(char *));
|
||||
for (i = 0; i < $1; i++) {
|
||||
C_word o = C_block_item ($input, i);
|
||||
if (!C_swig_is_string (o)) {
|
||||
char err[50];
|
||||
free($2);
|
||||
sprintf (err, "$input[%d] is not a string", i);
|
||||
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, err);
|
||||
}
|
||||
$2[i] = C_c_string (o);
|
||||
}
|
||||
$2[i] = 0;
|
||||
}
|
||||
|
||||
%typemap(chicken,freear) (int argc, char *argv[]) {
|
||||
free($2);
|
||||
}
|
||||
extern int gcdmain(int argc, char *argv[]);
|
||||
|
||||
%typemap(chicken,in) (char *bytes, int len) {
|
||||
if (!C_swig_is_string ($input)) {
|
||||
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument $input is not a string");
|
||||
}
|
||||
$1 = C_c_string ($input);
|
||||
$2 = C_header_size ($input);
|
||||
}
|
||||
|
||||
extern int count(char *bytes, int len, char c);
|
||||
|
||||
|
||||
/* This example shows how to wrap a function that mutates a string */
|
||||
|
||||
%typemap(chicken,in) (char *str, int len)
|
||||
%{ if (!C_swig_is_string ($input)) {
|
||||
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument $input is not a string");
|
||||
}
|
||||
$2 = C_header_size ($input);
|
||||
$1 = (char *) malloc ($2+1);
|
||||
memmove ($1, C_c_string ($input), $2);
|
||||
%}
|
||||
|
||||
/* Return the mutated string as a new object. Notice the if MANY construct ... they must be at column 0. */
|
||||
|
||||
%typemap(chicken,argout,fragment="list_output_helper",chicken_words="0") (char *str, int len) (C_word *scmstr)
|
||||
%{ scmstr = C_alloc (C_SIZEOF_STRING ($2));
|
||||
/*if MANY*/
|
||||
$result = list_output_helper (&known_space, $result, C_string (&scmstr, $2, $1));
|
||||
/*else*/
|
||||
$result = C_string (&scmstr, $2, $1);
|
||||
/*endif*/
|
||||
free ($1);
|
||||
%}
|
||||
|
||||
extern void capitalize (char *str, int len);
|
||||
|
||||
/* A multi-valued constraint. Force two arguments to lie
|
||||
inside the unit circle */
|
||||
|
||||
%typemap(check) (double cx, double cy) {
|
||||
double a = $1*$1 + $2*$2;
|
||||
if (a > 1.0) {
|
||||
SWIG_exception (SWIG_ValueError, "cx and cy must be in unit circle");
|
||||
}
|
||||
}
|
||||
|
||||
extern void circle (double cx, double cy);
|
||||
|
||||
/* Test out multiple return values */
|
||||
|
||||
extern int squareCubed (int n, int *OUTPUT);
|
||||
%{
|
||||
/* Returns n^3 and set n2 to n^2 */
|
||||
int squareCubed (int n, int *n2) {
|
||||
*n2 = n * n;
|
||||
return (*n2) * n;
|
||||
};
|
||||
%}
|
||||
24
SWIG/Examples/chicken/multimap/precsi.scm
Normal file
24
SWIG/Examples/chicken/multimap/precsi.scm
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
(declare (unit precsi))
|
||||
(declare (uses example))
|
||||
|
||||
;; display prelude to csi
|
||||
(display "multimap\n\n")
|
||||
|
||||
(display " A SWIG example for the CHICKEN compiler\n")
|
||||
(display " Author: Jonah Beckford, November 2002\n\n")
|
||||
|
||||
(display "C Procedures:\n")
|
||||
(display " int gcd (int n, int m);\n")
|
||||
(display " int gcdmain (int argc, char *argv[]);")
|
||||
(display " int count (char *bytes, int len, char c);")
|
||||
(display " void capitalize (char *str, int len);")
|
||||
(display " void circle (double x, double y);")
|
||||
(display "\n")
|
||||
|
||||
(display "Scheme Procedures:\n")
|
||||
(display " (example-gcd %n %m)\n")
|
||||
(display " (example-gcdmain '(%string %string ...))\n")
|
||||
(display " (example-count %string %character)\n")
|
||||
(display " (example-capitalize %string)\n")
|
||||
(display " (example-circle %x %y)\n")
|
||||
(display "\n")
|
||||
54
SWIG/Examples/chicken/multimap/test-multimap.scm
Normal file
54
SWIG/Examples/chicken/multimap/test-multimap.scm
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
;; run with './multimap test-multimap.scm'
|
||||
;; feel free to uncomment and comment sections
|
||||
|
||||
(display "(example-gcd 90 12): ")
|
||||
(display (example-gcd 90 12))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-gcd 90 'a): ")
|
||||
;;(display (example-gcd 90 'a))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-gcd 'b 12): ")
|
||||
;;(display (example-gcd 'b 12))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-circle 0.5 0.5): ")
|
||||
(example-circle 0.5 0.5)
|
||||
(display "\n")
|
||||
|
||||
(display "(example-circle 1.0 1.0): ")
|
||||
;;(example-circle 1.0 1.0)
|
||||
(display "\n")
|
||||
|
||||
(display "(example-circle 1 1): ")
|
||||
;;(example-circle 1 1)
|
||||
(display "\n")
|
||||
|
||||
(display "(example-capitalize \"will this be all capital letters?\"): ")
|
||||
(display (example-capitalize "will this be all capital letters?"))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-capitalize 'a): ")
|
||||
;;(display (example-capitalize 'a))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-count \"jumpity little spider\" #\\t): ")
|
||||
(display (example-count "jumpity little spider" #\t))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-gcdmain '#(\"hi\" \"there\")): ")
|
||||
(display (example-gcdmain '#("hi" "there")))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-gcdmain '#(\"gcd\" \"9\" \"28\")): ")
|
||||
(example-gcdmain '#("gcd" "9" "28"))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-gcdmain '#(\"gcd\" \"12\" \"90\")): ")
|
||||
(example-gcdmain '#("gcd" "12" "90"))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-squarecubed 3: ")
|
||||
(display (example-squarecubed 3))
|
||||
(display "\n")
|
||||
9
SWIG/Examples/chicken/overload/.cvsignore
Normal file
9
SWIG/Examples/chicken/overload/.cvsignore
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
*.dll
|
||||
*.dsw
|
||||
*.ncb
|
||||
*.opt
|
||||
*.plg
|
||||
Release
|
||||
Debug
|
||||
59
SWIG/Examples/chicken/overload/Makefile.in
Normal file
59
SWIG/Examples/chicken/overload/Makefile.in
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
@SET_MAKE@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
SOURCE_DIR = $(top_srcdir)/Examples/chicken/overload
|
||||
TOP = ../..
|
||||
CC = @CC@
|
||||
CXX = @CXX@
|
||||
OBJEXT = @OBJEXT@
|
||||
EXEEXT = @EXEEXT@
|
||||
SWIG = $(TOP)/../swig$(EXEEXT)
|
||||
CHICKGEN = example_wrap.$(OBJEXT) csi.$(OBJEXT) precsi.$(OBJEXT) \
|
||||
oexample.$(OBJEXT)
|
||||
CHICKSRC = csi.c precsi.c oexample.c
|
||||
SRCS = $(CHICKGEN) $(SOURCE_DIR)/example.cxx
|
||||
TARGET = overload$(EXEEXT)
|
||||
INCLUDE = -I$(SOURCE_DIR)
|
||||
SWIGOPT =
|
||||
|
||||
all:: $(TARGET) example_generic.scm example_clos.scm
|
||||
|
||||
.SUFFIXES: .cxx
|
||||
|
||||
.c.o:
|
||||
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
.cxx.o:
|
||||
$(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
csi.c:
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='csi.c' \
|
||||
INTERFACE='precsi' chicken_csi
|
||||
|
||||
precsi.c: $(SOURCE_DIR)/precsi.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='precsi.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
example_wrap.cxx example.scm example_generic.scm example_clos.scm: $(SOURCE_DIR)/example.i
|
||||
(test $< -nt example.i && cp -p $< example.i) || echo example.i is up-to-date
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
INCLUDE='$(INCLUDE)' INTERFACE='example.i' chicken_cpp
|
||||
|
||||
oexample.c: example.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='oexample.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
$(TARGET): $(SRCS)
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
|
||||
INTERFACE='$(INTERFACE)' chicken_cpp_static
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.$(OBJEXT) core *~ *.so *.stackdump STACKTRACE
|
||||
rm -f $(CHICKGEN) $(CHICKSRC)
|
||||
rm -f example.scm example_generic.scm example_clos.scm
|
||||
rm -f $(TARGET)
|
||||
|
||||
check: all
|
||||
2
SWIG/Examples/chicken/overload/README
Normal file
2
SWIG/Examples/chicken/overload/README
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Overloading example from Chapter 5.14 of SWIG Core Documentation for
|
||||
version 1.3.
|
||||
33
SWIG/Examples/chicken/overload/example.cxx
Normal file
33
SWIG/Examples/chicken/overload/example.cxx
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/* File : example.c */
|
||||
|
||||
#include "example.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void foo(int x) {
|
||||
printf("x is %d\n", x);
|
||||
}
|
||||
|
||||
void foo(char *x) {
|
||||
printf("x is '%s'\n", x);
|
||||
}
|
||||
|
||||
Foo::Foo () {
|
||||
myvar = 55;
|
||||
printf ("Foo constructor called\n");
|
||||
}
|
||||
|
||||
Foo::Foo (const Foo &) {
|
||||
myvar = 66;
|
||||
printf ("Foo copy constructor called\n");
|
||||
}
|
||||
|
||||
void Foo::bar (int x) {
|
||||
printf ("Foo::bar(x) method ... \n");
|
||||
printf("x is %d\n", x);
|
||||
}
|
||||
|
||||
void Foo::bar (char *s, int y) {
|
||||
printf ("Foo::bar(s,y) method ... \n");
|
||||
printf ("s is '%s'\n", s);
|
||||
printf ("y is %d\n", y);
|
||||
}
|
||||
14
SWIG/Examples/chicken/overload/example.h
Normal file
14
SWIG/Examples/chicken/overload/example.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/* File : example.h */
|
||||
|
||||
extern void foo (int x);
|
||||
extern void foo (char *x);
|
||||
|
||||
class Foo {
|
||||
private:
|
||||
int myvar;
|
||||
public:
|
||||
Foo();
|
||||
Foo(const Foo &); // Copy constructor
|
||||
void bar(int x);
|
||||
void bar(char *s, int y);
|
||||
};
|
||||
16
SWIG/Examples/chicken/overload/example.i
Normal file
16
SWIG/Examples/chicken/overload/example.i
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* Let "Foo" objects be converted back and forth from TinyCLOS into
|
||||
low-level CHICKEN SWIG procedures */
|
||||
|
||||
%typemap(clos_in) Foo * = SIMPLE_CLOS_OBJECT *;
|
||||
%typemap(clos_out) Foo * = SIMPLE_CLOS_OBJECT *;
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
57
SWIG/Examples/chicken/overload/precsi.scm
Normal file
57
SWIG/Examples/chicken/overload/precsi.scm
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
(declare (unit precsi))
|
||||
(declare (uses example))
|
||||
|
||||
(if (not (member "-quiet" (cdr (argv))))
|
||||
(begin
|
||||
;; display prelude to csi
|
||||
(display "overload\n\n")
|
||||
|
||||
(display " A SWIG example for the CHICKEN compiler\n")
|
||||
(display " Author: Jonah Beckford, December 2002\n\n")
|
||||
|
||||
(display "C++ Interface\n")
|
||||
(display "-------------\n")
|
||||
(display "
|
||||
extern void foo (int x);
|
||||
extern void foo (char *x);
|
||||
|
||||
class Foo {
|
||||
public:
|
||||
Foo();
|
||||
Foo(const Foo &); // Copy constructor
|
||||
void bar(int x);
|
||||
void bar(char *s, int y);
|
||||
};
|
||||
")
|
||||
|
||||
(display "\n")
|
||||
|
||||
(display "CHICKEN Low-Level Procedures\n")
|
||||
(display "----------------------------\n")
|
||||
(display "
|
||||
(example-foo %x-int)
|
||||
(example-foo %x-string)
|
||||
(define A-FOO (example-new-Foo))
|
||||
(define ANOTHER-FOO (example-new-Foo %foo)) ;; copy constructor
|
||||
(example-Foo-bar %foo %x-int)
|
||||
(example-Foo-bar %foo %s-string %y-int)
|
||||
")
|
||||
|
||||
(display "\n")
|
||||
|
||||
(display "TinyCLOS Classes\n")
|
||||
(display "----------------\n")
|
||||
(display "
|
||||
;; ALL generic methods must be included first
|
||||
(include \"example_generic\")
|
||||
;; After generic methods are defined, can include TinyCLOS code
|
||||
(include \"example_clos\")
|
||||
|
||||
(+example-foo+ %x-int)
|
||||
(+example-foo+ %x-string)
|
||||
(define A-FOO (make <example-Foo>))
|
||||
(define ANOTHER-FOO (make <example-Foo> %fooObject)) ;; copy constructor
|
||||
(-bar- %fooObject %x-int)
|
||||
(-bar- %fooObject %s-string %y-int)
|
||||
")
|
||||
(display "\n")))
|
||||
46
SWIG/Examples/chicken/overload/test-overload.scm
Normal file
46
SWIG/Examples/chicken/overload/test-overload.scm
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
;; This file demonstrates the overloading capabilities of SWIG
|
||||
|
||||
;; Low level
|
||||
;; ---------
|
||||
|
||||
(display "
|
||||
Trying low level code ...
|
||||
(example-foo 1)
|
||||
(example-foo \"some string\")
|
||||
(define A-FOO (example-new-Foo))
|
||||
(define ANOTHER-FOO (example-new-Foo A-FOO)) ;; copy constructor
|
||||
(example-Foo-bar A-FOO 2)
|
||||
(example-Foo-bar ANOTHER-FOO \"another string\" 3)
|
||||
")
|
||||
|
||||
(example-foo 1)
|
||||
(example-foo "some string")
|
||||
(define A-FOO (example-new-Foo))
|
||||
(define ANOTHER-FOO (example-new-Foo A-FOO)) ;; copy constructor
|
||||
(example-Foo-bar A-FOO 2)
|
||||
(example-Foo-bar ANOTHER-FOO "another string" 3)
|
||||
|
||||
;; TinyCLOS
|
||||
;; --------
|
||||
|
||||
(display "
|
||||
Trying TinyCLOS code ...
|
||||
(+example-foo+ 1)
|
||||
(+example-foo+ \"some string\")
|
||||
(define A-FOO (make <example-Foo>))
|
||||
(define ANOTHER-FOO (make <example-Foo> A-FOO)) ;; copy constructor
|
||||
(-bar- A-FOO 2)
|
||||
(-bar- ANOTHER-FOO \"another string\" 3)
|
||||
")
|
||||
|
||||
;; ALL generic methods must be included first
|
||||
(include "example_generic")
|
||||
;; After generic methods are defined, can include TinyCLOS code
|
||||
(include "example_clos")
|
||||
|
||||
(+example-foo+ 1)
|
||||
(+example-foo+ "some string")
|
||||
(define A-FOO (make <example-Foo>))
|
||||
(define ANOTHER-FOO (make <example-Foo> A-FOO)) ;; copy constructor
|
||||
(-bar- A-FOO 2)
|
||||
(-bar- ANOTHER-FOO "another string" 3)
|
||||
1
SWIG/Examples/chicken/simple/.cvsignore
Normal file
1
SWIG/Examples/chicken/simple/.cvsignore
Normal file
|
|
@ -0,0 +1 @@
|
|||
example_wrap.c
|
||||
59
SWIG/Examples/chicken/simple/Makefile.in
Normal file
59
SWIG/Examples/chicken/simple/Makefile.in
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
@SET_MAKE@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
SOURCE_DIR = $(top_srcdir)/Examples/chicken/simple
|
||||
TOP = ../..
|
||||
CC = @CC@
|
||||
CXX = @CXX@
|
||||
OBJEXT = @OBJEXT@
|
||||
EXEEXT = @EXEEXT@
|
||||
SWIG = $(TOP)/../swig$(EXEEXT)
|
||||
CHICKGEN = example_wrap.$(OBJEXT) csi.$(OBJEXT) precsi.$(OBJEXT) \
|
||||
oexample.$(OBJEXT)
|
||||
CHICKSRC = csi.c precsi.c oexample.c
|
||||
SRCS = $(CHICKGEN) $(SOURCE_DIR)/example.c
|
||||
TARGET = simple$(EXEEXT)
|
||||
INCLUDE = -I$(SOURCE_DIR)
|
||||
SWIGOPT =
|
||||
|
||||
all:: $(TARGET)
|
||||
|
||||
.SUFFIXES: .cxx
|
||||
|
||||
.c.o:
|
||||
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
.cxx.o:
|
||||
$(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
csi.c:
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='csi.c' \
|
||||
INTERFACE='precsi' chicken_csi
|
||||
|
||||
precsi.c: $(SOURCE_DIR)/precsi.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='precsi.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
example_wrap.c example.scm: $(SOURCE_DIR)/example.i
|
||||
(test $< -nt example.i && cp -p $< example.i) || echo example.i is up-to-date
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
INCLUDE='$(INCLUDE)' INTERFACE='example.i' chicken_c
|
||||
|
||||
oexample.c: example.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='oexample.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
$(TARGET): $(SRCS)
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
|
||||
INTERFACE='$(INTERFACE)' chicken_static
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.$(OBJEXT) core *~ *.so *.stackdump STACKTRACE
|
||||
rm -f $(CHICKGEN) $(CHICKSRC)
|
||||
rm -f example.scm
|
||||
rm -f $(TARGET)
|
||||
|
||||
check: all
|
||||
1
SWIG/Examples/chicken/simple/README
Normal file
1
SWIG/Examples/chicken/simple/README
Normal file
|
|
@ -0,0 +1 @@
|
|||
Simple example from users manual.
|
||||
24
SWIG/Examples/chicken/simple/example.c
Normal file
24
SWIG/Examples/chicken/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/chicken/simple/example.i
Normal file
13
SWIG/Examples/chicken/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();
|
||||
25
SWIG/Examples/chicken/simple/precsi.scm
Normal file
25
SWIG/Examples/chicken/simple/precsi.scm
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
(declare (unit precsi))
|
||||
(declare (uses example))
|
||||
|
||||
;; display prelude to csi
|
||||
(display "simple\n\n")
|
||||
|
||||
(display " A SWIG example for the CHICKEN compiler\n")
|
||||
(display " Author: Jonah Beckford, December 2002\n\n")
|
||||
|
||||
(display "C Procedures:\n")
|
||||
(display " double My_variable;\n")
|
||||
(display " int fact(int);\n")
|
||||
(display " %name(mod) int my_mod(int n, int m);\n")
|
||||
(display " int my_mod(int n, int m);\n")
|
||||
(display " char *get_time();\n")
|
||||
|
||||
(display "\n")
|
||||
|
||||
(display "Scheme Procedures:\n")
|
||||
(display " (example-My-variable) or (example-My-variable %x)\n");
|
||||
(display " (example-fact %n)\n")
|
||||
(display " (example-mod %n %m)\n")
|
||||
(display " (example-my-mod %n %m)\n")
|
||||
(display " (example-get-time)\n")
|
||||
(display "\n")
|
||||
43
SWIG/Examples/chicken/simple/test-simple.scm
Normal file
43
SWIG/Examples/chicken/simple/test-simple.scm
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
;; run with './simple test-simple.scm'
|
||||
;; feel free to uncomment and comment sections
|
||||
|
||||
(display "(example-My-variable): ")
|
||||
(display (example-My-variable))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-My-variable 3.141259): ")
|
||||
(display (example-My-variable 3.141259))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-My-variable): ")
|
||||
(display (example-My-variable))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-My-variable 'a): ")
|
||||
;;(display (example-My-variable 'a))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-My-variable 1.5 'b): ")
|
||||
(display (example-My-variable 1.5 'b))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-fact 5): ")
|
||||
(display (example-fact 5))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-fact 'a): ")
|
||||
;;(display (example-fact 'a))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-mod 75 7): ")
|
||||
(display (example-mod 75 7))
|
||||
(display "\n")
|
||||
|
||||
(display "(example-my-mod 75 7): ")
|
||||
(display (example-my-mod 75 7))
|
||||
(display "\n")
|
||||
|
||||
|
||||
(display "(example-get-time): ")
|
||||
(display (example-get-time))
|
||||
(display "\n")
|
||||
1
SWIG/Examples/chicken/vtk/.cvsignore
Normal file
1
SWIG/Examples/chicken/vtk/.cvsignore
Normal file
|
|
@ -0,0 +1 @@
|
|||
example_wrap.c
|
||||
170
SWIG/Examples/chicken/vtk/Makefile.in
Normal file
170
SWIG/Examples/chicken/vtk/Makefile.in
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
@SET_MAKE@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
SOURCE_DIR = $(top_srcdir)/Examples/chicken/vtk
|
||||
TOP = ../..
|
||||
CC = @CC@
|
||||
CXX = @CXX@
|
||||
OBJEXT = @OBJEXT@
|
||||
EXEEXT = @EXEEXT@
|
||||
CMAKEVER = cmake-1.6.2
|
||||
THISDIR = $(PWD)
|
||||
VTKVER = 40
|
||||
VTKHOME = $(PWD)/vtklocal
|
||||
SWIG = $(TOP)/../swig$(EXEEXT)
|
||||
CHICKGEN = example_wrap.$(OBJEXT) csi.$(OBJEXT) precsi.$(OBJEXT) \
|
||||
oexample.$(OBJEXT)
|
||||
CHICKSRC = csi.c precsi.c oexample.c
|
||||
SRCS = $(CHICKGEN)
|
||||
TARGET = vtk$(EXEEXT)
|
||||
INCLUDE = -I$(SOURCE_DIR) -I$(VTKHOME)/include/vtk
|
||||
EXTRALIBS = -lgdi32 -lopengl32
|
||||
LIBS = -L$(VTKHOME)/lib/vtk -lvtkRendering -lvtkIO -lvtkGraphics \
|
||||
-lvtkImaging -lvtkFiltering -lvtkCommon -lvtkjpeg -lvtkpng \
|
||||
-lvtkzlib $(EXTRALIBS)
|
||||
SWIGOPT = -mixed $(INCLUDE)
|
||||
BTXETX = vtkFieldData.i vtkDataSetAttributes.i
|
||||
|
||||
# Symbols used for using shared libraries
|
||||
SO = @SO@
|
||||
LDSHARED = @LDSHARED@
|
||||
CXXSHARED = @CXXSHARED@
|
||||
|
||||
# This is used for building shared libraries with a number of C++
|
||||
# compilers. If it doesn't work, comment it out.
|
||||
@TRYLINKINGWITHCXX@
|
||||
|
||||
all:: $(TARGET) example_generic.scm example_clos.scm
|
||||
|
||||
.SUFFIXES: .cxx
|
||||
|
||||
.c.o:
|
||||
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
.cxx.o:
|
||||
$(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
csi.c:
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='csi.c' \
|
||||
INTERFACE='precsi' chicken_csi
|
||||
|
||||
precsi.c: $(SOURCE_DIR)/precsi.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='precsi.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
example_wrap.cxx example.scm example_generic.scm example_clos.scm: $(SOURCE_DIR)/example.i $(BTXETX)
|
||||
(test $< -nt example.i && cp -p $< example.i) || echo example.i is up-to-date
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
INCLUDE='$(INCLUDE)' INTERFACE='example.i' chicken_cpp
|
||||
|
||||
oexample.c: example.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='oexample.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
$(TARGET): $(SRCS)
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
|
||||
LIBS='$(LIBS)' INTERFACE='$(INTERFACE)' chicken_cpp_static
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.o core *~ *.so *.stackdump STACKTRACE
|
||||
rm -f $(CHICKGEN) $(CHICKSRC)
|
||||
rm -f $(BTXETX) example.scm example_generic.scm example_clos.scm
|
||||
rm -f $(TARGET) c-sphere$(EXEEXT) c-quadric$(EXEEXT)
|
||||
@echo
|
||||
@echo You can clean VTK with: cd vtk$(VTKVER)/VTK '&&' make clean
|
||||
@echo You can clean CMake with: cd $(CMAKEVER) '&&' make clean
|
||||
|
||||
check:
|
||||
|
||||
btx-etx::
|
||||
@sed "s^//BTX^#if 0\/* start BTX <-> ETX */^g ;\
|
||||
s^//ETX^#endif /* end BTX <-> ETX */^g" \
|
||||
$(SOURCE) > $(DEST)
|
||||
|
||||
vtkFieldData.i: $(VTKHOME)/include/vtk/vtkFieldData.h
|
||||
$(MAKE) SOURCE="$<" DEST="$@" btx-etx
|
||||
|
||||
vtkDataSetAttributes.i: $(VTKHOME)/include/vtk/vtkDataSetAttributes.h
|
||||
$(MAKE) SOURCE="$<" DEST="$@" btx-etx
|
||||
|
||||
cmake: $(CMAKEVER).tar.gz
|
||||
gunzip -d -c $(CMAKEVER).tar.gz | tar xvf - && \
|
||||
cd $(CMAKEVER) && \
|
||||
./configure --prefix $(THISDIR)/cmakelocal && \
|
||||
make && \
|
||||
make install
|
||||
|
||||
vtkunix: vtk$(VTKVER)Src.tar.gz
|
||||
mkdir vtk$(VTKVER) || echo Rebuilding VTK
|
||||
cd vtk$(VTKVER) && \
|
||||
gunzip -d -c ../vtk$(VTKVER)Src.tar.gz | tar xvf - && \
|
||||
rm -f VTK/CMakeCache.txt && \
|
||||
cd VTK && \
|
||||
mv Utilities/Doxygen/doxyfile.in Utilities/Doxygen/doxyfile.in.orig && \
|
||||
sed 's^GENERATE_\([A-Z]*[ ]*=[ ]*\)YES^GENERATE_\1NO^; $$ a GENERATE_XML = YES' Utilities/Doxygen/doxyfile.in.orig > Utilities/Doxygen/doxyfile.in && \
|
||||
cmake . \
|
||||
-DCMAKE_C_COMPILER:FILEPATH="$(CC)" \
|
||||
-DCMAKE_C_LINK_SHARED:STRING="$(LDSHARED)" \
|
||||
-DCMAKE_CXX_COMPILER:FILEPATH="$(CXX)" \
|
||||
-DCMAKE_CXX_LINK_SHARED:STRING="$(CXXSHARED)" \
|
||||
-DCMAKE_CXX_SHLIB_BUILD_FLAGS:STRING= \
|
||||
-DCMAKE_CXX_MODULE_BUILD_FLAGS:STRING= \
|
||||
-DCMAKE_MODULE_BUILD_FLAGS:STRING= \
|
||||
-DCMAKE_MODULE_SUFFIX:STRING="$(SO)" \
|
||||
-DCMAKE_SHLIB_BUILD_FLAGS:STRING= \
|
||||
-DCMAKE_SHLIB_SUFFIX:STRING="$(SO)" \
|
||||
-DCMAKE_MAKE_PROGRAM:FILEPATH="$(MAKE)" \
|
||||
-DCMAKE_INSTALL_PREFIX:PATH="$(THISDIR)/vtklocal" \
|
||||
-DCMAKE_BACKWARDS_COMPATIBILITY:STRING=1.2 \
|
||||
-DBUILD_DOCUMENTATION:BOOL=ON \
|
||||
-DBUILD_SHARED_LIBS:BOOL=ON \
|
||||
-DBUILD_EXAMPLES:BOOL=ON && \
|
||||
make && \
|
||||
make install
|
||||
|
||||
# cygwin has OpenGL from the Windows API and X. We force it to use
|
||||
# the Windows API so there is no conflict.
|
||||
vtkcygwin: vtk$(VTKVER)Src.tar.gz
|
||||
mkdir vtk$(VTKVER) || echo Rebuilding VTK
|
||||
cd vtk$(VTKVER) && \
|
||||
gunzip -d -c ../vtk$(VTKVER)Src.tar.gz | tar xvf - && \
|
||||
rm -f VTK/CMakeCache.txt && \
|
||||
cd VTK && \
|
||||
mv Utilities/Doxygen/doxyfile.in Utilities/Doxygen/doxyfile.in.orig && \
|
||||
sed 's^GENERATE_\([A-Z]*[ ]*=[ ]*\)YES^GENERATE_\1NO^; $$ a GENERATE_XML = YES' Utilities/Doxygen/doxyfile.in.orig > Utilities/Doxygen/doxyfile.in && \
|
||||
mv Common/vtkViewport.h Common/vtkViewport.h.orig && \
|
||||
sed -f ../../cygwin_viewport.sed Common/vtkViewport.h.orig > Common/vtkViewport.h && \
|
||||
cmake . \
|
||||
-DCMAKE_C_COMPILER:FILEPATH="$(CC)" \
|
||||
-DCMAKE_C_LINK_SHARED:STRING="$(LDSHARED)" \
|
||||
-DCMAKE_CXX_COMPILER:FILEPATH="$(CXX)" \
|
||||
-DCMAKE_CXX_LINK_SHARED:STRING="$(CXXSHARED)" \
|
||||
-DCMAKE_CXX_SHLIB_BUILD_FLAGS:STRING= \
|
||||
-DCMAKE_CXX_MODULE_BUILD_FLAGS:STRING= \
|
||||
-DCMAKE_MODULE_BUILD_FLAGS:STRING= \
|
||||
-DCMAKE_MODULE_SUFFIX:STRING="$(SO)" \
|
||||
-DCMAKE_SHLIB_BUILD_FLAGS:STRING= \
|
||||
-DCMAKE_SHLIB_SUFFIX:STRING="$(SO)" \
|
||||
-DCMAKE_MAKE_PROGRAM:FILEPATH="$(MAKE)" \
|
||||
-DCMAKE_X_CFLAGS:STRING=" -I/usr/include/w32api -I/usr/X11R6/include " \
|
||||
-DCMAKE_INSTALL_PREFIX:PATH="$(THISDIR)/vtklocal" \
|
||||
-DCMAKE_BACKWARDS_COMPATIBILITY:STRING=1.2 \
|
||||
-DBUILD_DOCUMENTATION:BOOL=ON \
|
||||
-DBUILD_SHARED_LIBS:BOOL=ON \
|
||||
-DBUILD_EXAMPLES:BOOL=ON && \
|
||||
make && \
|
||||
make install
|
||||
|
||||
vtkdoc: vtk$(VTKVER)/VTK/Utilities/Doxygen/Makefile
|
||||
$(MAKE) -f $< DoxygenDoc
|
||||
|
||||
c: c-sphere$(EXEEXT) c-quadric$(EXEEXT)
|
||||
|
||||
c-sphere$(EXEEXT): c-sphere.o
|
||||
$(CXX) $< $(LIBS) -o $@
|
||||
|
||||
c-quadric$(EXEEXT): c-quadric.o
|
||||
$(CXX) $< $(LIBS) -o $@
|
||||
136
SWIG/Examples/chicken/vtk/README
Normal file
136
SWIG/Examples/chicken/vtk/README
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
Wrappers for the Visualization Toolkit (VTK).
|
||||
|
||||
VTK must be installed first.
|
||||
|
||||
VTK Installation Instructions
|
||||
-----------------------------
|
||||
|
||||
Warning to GCC users:
|
||||
|
||||
GCC version 3 cannot be used to compile VTK; you may check the version
|
||||
of gcc with "gcc -version". GCC version 3 is the default compiler on
|
||||
recent cygwin systems, and is used on some other newer systems as
|
||||
well. Be sure that you have another compiler or GCC version 2 on your
|
||||
system (for example, the package "gcc2" on cygwin). You will specify
|
||||
your other compiler on *ALL* commands that start with "make". For
|
||||
example, if you have the "gcc2" package on cygwin, when you get to the
|
||||
following VTK build instruction:
|
||||
|
||||
make VTKVER=40 vtkcygwin
|
||||
|
||||
use instead:
|
||||
|
||||
make VTKVER=40 CC="gcc-2" CXX="c++-2" LDSHARED="gcc-2 -shared" CXXSHARED="c++-2 -shared" vtkcygwin
|
||||
|
||||
On non-cygwin system, the VTK build instruction:
|
||||
|
||||
make VTKVER=40 vtkunix
|
||||
|
||||
would be replaced by:
|
||||
|
||||
make VTKVER=40 CC="<path to non-gcc3 C compiler>" CXX="<path to non-gcc3 C++ compiler>" LDSHARED="<path to non-gcc3 C shared linker>" CXXSHARED="<path to non-gcc3 C++ shared linker>" vtkunix
|
||||
|
||||
and so on ...
|
||||
|
||||
GENERAL NOTE: At this moment, Common/vtkViewport.o is not included in
|
||||
libCommon.a for VTK 4.0. This causes problems and is an obvious
|
||||
mistake. So the Makefile looks for vtkViewport.o in the
|
||||
vtk40/VTK/Common directory when building this SWIG example. So only
|
||||
Method 3 is an option right now (or Method 2 if you copy vtkViewport.o
|
||||
to .../chicken/vtk/vtk40/VTK/Common/).
|
||||
|
||||
|
||||
-- Method 1 (Win32 with mingw) --
|
||||
|
||||
Download vtk40Core.exe and vtkCpp.exe from
|
||||
http://public.kitware.com/VTK/get-software.php.
|
||||
|
||||
Run vtk40Core.exe and install to wherever (I will assume you
|
||||
installed to the default "C:\Program Files\vtk4.0").
|
||||
|
||||
Run vtkCpp.exe and install to the same directory you install
|
||||
vtk40Core.
|
||||
|
||||
Before building this SWIG example, set
|
||||
VTKHOME=C:\Program Files\vtk4.0
|
||||
|
||||
and then run "make" in this chicken/vtk directory using Mingw32 (that
|
||||
is, run Cygwin shell, and set the PATH to .../mingw/bin).
|
||||
|
||||
-- Method 2 --
|
||||
|
||||
Download a source archive (either vtk40Src.zip or vtk40Src.tar.gz)
|
||||
from http://public.kitware.com/VTK/get-software.php and follow the
|
||||
instructions using "README.html" (which is inside vtk40Src).
|
||||
|
||||
-- Method 3 (Unix or Cygwin) --
|
||||
|
||||
If you do not have "cmake" installed on your system, do the following
|
||||
and it will be installed in chicken/vtk/cmakelocal:
|
||||
|
||||
Download
|
||||
|
||||
cmake-1.6.2.tar.gz from
|
||||
http://www.cmake.org/HTML/Download.html
|
||||
|
||||
and place it in this chicken/vtk directory.
|
||||
|
||||
Type:
|
||||
make CMAKEVER=cmake-1.6.2 cmake
|
||||
PATH=${PWD}/cmakelocal/bin:$PATH
|
||||
export PATH
|
||||
|
||||
If you do not have "vtk" installed on your system, do the following
|
||||
and it will be installed in chicken/vtk/vtklocal:
|
||||
|
||||
Download
|
||||
|
||||
vtk40Src.tar.gz from
|
||||
http://public.kitware.com/VTK/get-software.php
|
||||
|
||||
and place it in this chicken/vtk directory.
|
||||
|
||||
Type (for cygwin):
|
||||
make VTKVER=40 vtkcygwin
|
||||
|
||||
(for everyone else):
|
||||
make VTKVER=40 vtkunix
|
||||
|
||||
VTK SWIG Example
|
||||
----------------
|
||||
|
||||
Make sure that VTK is installed. If you followed the previous
|
||||
instructions, then VTK will be installed in .../chicken/vtk/vtklocal.
|
||||
The following instructions will assume ${PWD}/vtklocal; if you
|
||||
installed VTK elsewhere, use the correct installation path
|
||||
(ie. /usr/local instead of ${PWD}/vtklocal).
|
||||
|
||||
First, test to make sure VTK is working ...
|
||||
|
||||
cygwin:
|
||||
make EXTRALIBS="-lgdi32 -lopengl32" VTKHOME=${PWD}/vtklocal c
|
||||
./c-sphere.exe
|
||||
./c-quadric.exe
|
||||
|
||||
other Unixes:
|
||||
make EXTRALIBS="-L/usr/X11R6/lib -lGL -lGLU -lGLw" VTKHOME=${PWD}/vtklocal c
|
||||
./c-sphere
|
||||
./c-quadric
|
||||
|
||||
|
||||
You should see a blue sphere that you can manipulate with the mouse
|
||||
buttons.
|
||||
|
||||
Second, test to make sure the SWIG wrappers can be generated and work
|
||||
for VTK ...
|
||||
|
||||
cygwin:
|
||||
make EXTRALIBS="-lgdi32 -lopengl32" VTKHOME=${PWD}/vtklocal
|
||||
./vtk test-vtk-sphere.scm
|
||||
./vtk test-vtk-quadric.scm
|
||||
|
||||
other Unixes:
|
||||
make EXTRALIBS="-L/usr/X11R6/lib -lGL -lGLU -lGLw" VTKHOME=${PWD}/vtklocal
|
||||
./vtk test-vtk-sphere.scm
|
||||
./vtk test-vtk-quadric.scm
|
||||
|
||||
74
SWIG/Examples/chicken/vtk/c-quadric.cxx
Normal file
74
SWIG/Examples/chicken/vtk/c-quadric.cxx
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#include "vtkQuadric.h"
|
||||
#include "vtkSampleFunction.h"
|
||||
#include "vtkContourFilter.h"
|
||||
#include "vtkOutlineFilter.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkActor.h"
|
||||
#include "vtkRenderWindow.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkRenderWindowInteractor.h"
|
||||
|
||||
void main ()
|
||||
{
|
||||
// -- create the quadric function object --
|
||||
|
||||
// create the quadric function definition
|
||||
vtkQuadric *quadric = vtkQuadric::New();
|
||||
quadric->SetCoefficients(.5,1,.2,0,.1,0,0,.2,0,0);
|
||||
|
||||
// sample the quadric function
|
||||
vtkSampleFunction *sample = vtkSampleFunction::New();
|
||||
sample->SetSampleDimensions(50,50,50);
|
||||
sample->SetImplicitFunction(quadric);
|
||||
|
||||
// Create five surfaces F(x,y,z) = constant between range specified
|
||||
vtkContourFilter *contours = vtkContourFilter::New();
|
||||
contours->SetInput(sample->GetOutput());
|
||||
contours->GenerateValues(5, 0.0, 1.2);
|
||||
|
||||
// map the contours to graphical primitives
|
||||
vtkPolyDataMapper *contMapper = vtkPolyDataMapper::New();
|
||||
contMapper->SetInput(contours->GetOutput());
|
||||
contMapper->SetScalarRange(0.0, 1.2);
|
||||
|
||||
// create an actor for the contours
|
||||
vtkActor *contActor = vtkActor::New();
|
||||
contActor->SetMapper(contMapper);
|
||||
|
||||
// -- create a box around the function to indicate the sampling volume --
|
||||
|
||||
// create outline
|
||||
vtkOutlineFilter *outline = vtkOutlineFilter::New();
|
||||
outline->SetInput(sample->GetOutput());
|
||||
|
||||
// map it to graphics primitives
|
||||
vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
|
||||
outlineMapper->SetInput(outline->GetOutput());
|
||||
|
||||
// create an actor for it
|
||||
vtkActor *outlineActor = vtkActor::New();
|
||||
outlineActor->SetMapper(outlineMapper);
|
||||
outlineActor->GetProperty()->SetColor(0,0,0);
|
||||
|
||||
// -- render both of the objects --
|
||||
|
||||
// a renderer and render window
|
||||
vtkRenderer *ren1 = vtkRenderer::New();
|
||||
vtkRenderWindow *renWin = vtkRenderWindow::New();
|
||||
renWin->AddRenderer(ren1);
|
||||
|
||||
// an interactor
|
||||
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
|
||||
iren->SetRenderWindow(renWin);
|
||||
|
||||
// add the actors to the scene
|
||||
ren1->AddActor(contActor);
|
||||
ren1->AddActor(outlineActor);
|
||||
ren1->SetBackground(1,1,1); // Background color white
|
||||
|
||||
// render an image (lights and cameras are created automatically)
|
||||
renWin->Render();
|
||||
|
||||
// begin mouse interaction
|
||||
iren->Start();
|
||||
}
|
||||
46
SWIG/Examples/chicken/vtk/c-sphere.cxx
Normal file
46
SWIG/Examples/chicken/vtk/c-sphere.cxx
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#include "vtkSphereSource.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkActor.h"
|
||||
#include "vtkRenderWindow.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkRenderWindowInteractor.h"
|
||||
|
||||
int main ()
|
||||
{
|
||||
|
||||
// create sphere geometry
|
||||
vtkSphereSource *sphere = vtkSphereSource::New();
|
||||
sphere->SetRadius(1.0);
|
||||
sphere->SetThetaResolution(18);
|
||||
sphere->SetPhiResolution(18);
|
||||
|
||||
// map to graphics library
|
||||
vtkPolyDataMapper *map = vtkPolyDataMapper::New();
|
||||
map->SetInput(sphere->GetOutput());
|
||||
|
||||
// actor coordinates geometry, properties, transformation
|
||||
vtkActor *aSphere = vtkActor::New();
|
||||
aSphere->SetMapper(map);
|
||||
aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue
|
||||
|
||||
// a renderer and render window
|
||||
vtkRenderer *ren1 = vtkRenderer::New();
|
||||
vtkRenderWindow *renWin = vtkRenderWindow::New();
|
||||
renWin->AddRenderer(ren1);
|
||||
|
||||
// an interactor
|
||||
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
|
||||
iren->SetRenderWindow(renWin);
|
||||
|
||||
// add the actor to the scene
|
||||
ren1->AddActor(aSphere);
|
||||
ren1->SetBackground(1,1,1); // Background color white
|
||||
|
||||
// render an image (lights and cameras are created automatically)
|
||||
renWin->Render();
|
||||
|
||||
// begin mouse interaction
|
||||
iren->Start();
|
||||
|
||||
return 0;
|
||||
}
|
||||
7
SWIG/Examples/chicken/vtk/cygwin_viewport.sed
Normal file
7
SWIG/Examples/chicken/vtk/cygwin_viewport.sed
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/class VTK_COMMON_EXPORT vtkViewport/ {
|
||||
i /* cygwin: /usr/include/w32api/winuser.h redefines RemoveProp */\
|
||||
#ifdef RemoveProp\
|
||||
#undef RemoveProp\
|
||||
#endif\
|
||||
|
||||
}
|
||||
335
SWIG/Examples/chicken/vtk/example.i
Normal file
335
SWIG/Examples/chicken/vtk/example.i
Normal file
|
|
@ -0,0 +1,335 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
/* STANDARD VTK CLASSES */
|
||||
|
||||
%{
|
||||
/* Put headers and other declarations here. SWIG does not parse this
|
||||
section. */
|
||||
#include "vtkConfigure.h"
|
||||
#include "vtkSystemIncludes.h"
|
||||
#ifdef VTK_MAJOR_VERSION
|
||||
/* only defined since Nov 19 2002, just after 4.0 release */
|
||||
#include "vtkObjectBase.h"
|
||||
#endif
|
||||
#include "vtkIndent.h"
|
||||
#include "vtkTimeStamp.h"
|
||||
#include "vtkSetGet.h"
|
||||
#include "vtkObject.h"
|
||||
#include "vtkCommand.h"
|
||||
#include "vtkDataArray.h"
|
||||
#include "vtkIdList.h"
|
||||
#include "vtkFieldData.h"
|
||||
#include "vtkDataObject.h"
|
||||
#include "vtkDataSetAttributes.h"
|
||||
#include "vtkCellData.h"
|
||||
#include "vtkPointData.h"
|
||||
#include "vtkCell.h"
|
||||
#include "vtkGenericCell.h"
|
||||
#include "vtkCellTypes.h"
|
||||
#include "vtkDataSet.h"
|
||||
#include "vtkLocator.h"
|
||||
#include "vtkPoints.h"
|
||||
#include "vtkPointLocator.h"
|
||||
#include "vtkPointSet.h"
|
||||
#include "vtkCellArray.h"
|
||||
#include "vtkCellLinks.h"
|
||||
#include "vtkProcessObject.h"
|
||||
#include "vtkSource.h"
|
||||
#include "vtkPolyData.h"
|
||||
#include "vtkPolyDataSource.h"
|
||||
#include "vtkSphereSource.h"
|
||||
#include "vtkCollection.h"
|
||||
#include "vtkImplicitFunction.h"
|
||||
#include "vtkPlane.h"
|
||||
#include "vtkPlaneCollection.h"
|
||||
#include "vtkPlanes.h"
|
||||
#include "vtkTimerLog.h"
|
||||
#include "vtkAbstractMapper.h"
|
||||
#include "vtkAbstractMapper3D.h"
|
||||
#include "vtkScalarsToColors.h"
|
||||
#include "vtkMapper.h"
|
||||
#include "vtkQuadric.h"
|
||||
#include "vtkImageSource.h"
|
||||
#include "vtkImageData.h"
|
||||
#include "vtkStructuredPoints.h"
|
||||
#include "vtkStructuredPointsSource.h"
|
||||
#include "vtkSampleFunction.h"
|
||||
#include "vtkDataSetToPolyDataFilter.h"
|
||||
#include "vtkContourValues.h"
|
||||
#include "vtkContourFilter.h"
|
||||
#include "vtkOutlineFilter.h"
|
||||
#include "vtkPolyDataMapper.h"
|
||||
#include "vtkProp.h"
|
||||
#include "vtkProp3D.h"
|
||||
#include "vtkProperty.h"
|
||||
#include "vtkTexture.h"
|
||||
#include "vtkActor.h"
|
||||
#include "vtkWindow.h"
|
||||
#include "vtkRendererCollection.h"
|
||||
#include "vtkGraphicsFactory.h"
|
||||
#include "vtkRenderWindow.h"
|
||||
#include "vtkMatrix4x4.h"
|
||||
#include "vtkLightCollection.h"
|
||||
#include "vtkPropCollection.h"
|
||||
#include "vtkVolumeCollection.h"
|
||||
#include "vtkCullerCollection.h"
|
||||
#include "vtkCamera.h"
|
||||
#include "vtkActor2D.h"
|
||||
#include "vtkViewport.h"
|
||||
#include "vtkActorCollection.h"
|
||||
#include "vtkRenderer.h"
|
||||
#include "vtkRenderWindowInteractor.h"
|
||||
%}
|
||||
|
||||
%include typemaps.i
|
||||
|
||||
#define VTK_COMMON_EXPORT
|
||||
#define VTK_FILTERING_EXPORT
|
||||
#define VTK_GRAPHICS_EXPORT
|
||||
#define VTK_IMAGING_EXPORT
|
||||
#define VTK_RENDERING_EXPORT
|
||||
|
||||
|
||||
/* We need a way to convert the input and output arguments that are
|
||||
VTK objects into TinyCLOS objects, and vice versa. We can use the
|
||||
clos_in and clos_out typemaps for this. Just specify the typemaps
|
||||
for classes that are at the top of the inheritance tree.
|
||||
|
||||
We have things quite easy because VTK handles object deletion with
|
||||
reference counting (so we don't have to make a finalizer procedure
|
||||
for the garbage collector), and because most of the classes derive
|
||||
from vtkObjectBase or vtkObject.
|
||||
|
||||
In post VTK 4.0 releases, most things derive from vtkObjectBase.
|
||||
In other releases, things come from vtkObject. */
|
||||
#ifdef VTK_MAJOR_VERSION
|
||||
/* only defined since Nov 19 2002, just after 4.0 release */
|
||||
%typemap("clos_in") vtkObjectBase * = SIMPLE_CLOS_OBJECT *;
|
||||
%typemap("clos_out") vtkObjectBase * = SIMPLE_CLOS_OBJECT *;
|
||||
#else
|
||||
%typemap("clos_in") vtkObject * = SIMPLE_CLOS_OBJECT *;
|
||||
%typemap("clos_out") vtkObject * = SIMPLE_CLOS_OBJECT *;
|
||||
#endif
|
||||
%apply SIMPLE_CLOS_OBJECT * {
|
||||
vtkIndent*, vtkTimeStamp*, vtkCollectionElement*, vtkTimerLogEntry*,
|
||||
vtkCommand*, _vtkLink_s*
|
||||
};
|
||||
|
||||
/* We have one problem with the above typemaps ... they assume that
|
||||
SWIG can know that a given class is derived from one of the above
|
||||
superclasses (like derived from vtkObjectBase). However, sometimes
|
||||
SWIG will get to a function or member declaration that relies some
|
||||
object that was forward declared. For example,
|
||||
|
||||
class vtkRenderer;
|
||||
class vtkRenderWindow {
|
||||
// ...
|
||||
virtual void AddRenderer (vtkRenderer *rendererArg);
|
||||
// ...
|
||||
};
|
||||
|
||||
In this case, SWIG cannot know that vtkRenderer is derived from
|
||||
vtkObject, and hence will not put a TinyCLOS clos_in/clos_out
|
||||
converter around "rendererArg" (instead, you will have to pass in a
|
||||
low-level SWIG CHICKEN object pointer).
|
||||
|
||||
To help SWIG out, we explicitly define clos_in/clos_out typemaps
|
||||
for some of the classes that are forward declared.
|
||||
*/
|
||||
%apply SIMPLE_CLOS_OBJECT * {
|
||||
vtkRenderer*
|
||||
};
|
||||
|
||||
/* The -mixed command line argument for SWIG will screw up on esoteric
|
||||
names (with two upcase characters in a row) like below. Example:
|
||||
GetMTime becomes get-mt-ime, but if we rename it to Get_M_Time, it
|
||||
becomes get-m-time. So we help it along by putting in
|
||||
underscores. */
|
||||
%rename GetMTime Get_M_Time;
|
||||
%rename SetMTime Set_M_Time;
|
||||
%rename ShouldIReleaseData Should_I_Release_Data;
|
||||
%rename SetPipelineMTime Set_Pipeline_M_Time;
|
||||
%rename GetPipelineMTime Get_Pipeline_M_Time;
|
||||
%rename SetActiveTCoords Set_Active_T_Coords;
|
||||
%rename GetActiveTCoords Get_Active_T_Coords;
|
||||
%rename SetTCoords Set_T_Coords;
|
||||
%rename GetTCoords Get_T_Coords;
|
||||
%rename SetCopyTCoords Set_Copy_T_Coords;
|
||||
%rename GetCopyTCoords Get_Copy_T_Coords;
|
||||
%rename HitBBox Hit_B_Box;
|
||||
%rename IsARenderIntoImageMapper Is_A_Render_Into_Image_Mapper;
|
||||
%rename IsARayCastMapper Is_A_Ray_Cast_Mapper;
|
||||
%rename GetRedrawMTime Get_Redraw_M_Time;
|
||||
%rename SetRedrawMTime Set_Redraw_M_Time;
|
||||
%rename GetXRange Get_X_Range;
|
||||
%rename SetXRange Set_X_Range;
|
||||
%rename GetYRange Get_Y_Range;
|
||||
%rename SetYRange Set_Y_Range;
|
||||
%rename GetZRange Get_Z_Range;
|
||||
%rename SetZRange Set_Z_Range;
|
||||
%rename GetDPIMinValue Get_DPI_Min_Value;
|
||||
%rename SetDPIMinValue Set_DPI_Min_Value;
|
||||
%rename GetDPIMaxValue Get_DPI_Max_Value;
|
||||
%rename SetDPIMaxValue Set_DPI_Max_Value;
|
||||
%rename GetRGBAPixelData Get_RGBA_Pixel_Data;
|
||||
%rename SetRGBAPixelData Set_RGBA_Pixel_Data;
|
||||
%rename GetRGBACharPixelData Get_RGBA_Char_Pixel_Data;
|
||||
%rename SetRGBACharPixelData Set_RGBA_Char_Pixel_Data;
|
||||
%rename GetAAFrames Get_AA_Frames;
|
||||
%rename SetAAFrames Set_AA_Frames;
|
||||
%rename GetFDFrames Get_FD_Frames;
|
||||
%rename SetFDFrames Set_FD_Frames;
|
||||
|
||||
/* Things that are too difficult to wrap: We have 2 general mechanisms
|
||||
to exclude the difficult classes and/or methods from SWIG.
|
||||
|
||||
1. Write an SWIG interface file (we use a .i suffix) that is a
|
||||
copy of the header file with the difficult parts removed.
|
||||
|
||||
2. Use "%ignore" directives, before SWIG parses the relevant
|
||||
class/method/function/variable declaration. Example:
|
||||
|
||||
%ignore vtkDataSet::POINT_DATA_FIELD;
|
||||
%ignore someVariable;
|
||||
%ignore someFunction;
|
||||
%ignore someMethod;
|
||||
%ignore someClass;
|
||||
%ignore someClass::someMethod;
|
||||
|
||||
Now it so happens that VTK already comes with its own
|
||||
Python/TCL/Java wrapper modules, and the difficult sections have
|
||||
already been marked in the header files. VTK uses //BTX to mark
|
||||
the beginning of a difficult section, and //ETX to mark the end.
|
||||
So we use a simple 'sed' script to change //BTX to "#if 0" and
|
||||
//ETX to "#endif", and place the result in a .i file. This is done
|
||||
by the "btx-etx" Makefile target.
|
||||
|
||||
*/
|
||||
|
||||
%include "vtkConfigure.h"
|
||||
%include "vtkSystemIncludes.h"
|
||||
#ifdef VTK_MAJOR_VERSION
|
||||
/* only defined since Nov 19 2002, just after 4.0 release */
|
||||
%include "vtkObjectBase.h"
|
||||
#endif
|
||||
%include "vtkIndent.h"
|
||||
%include "vtkTimeStamp.h"
|
||||
%include "vtkSetGet.h"
|
||||
%include "vtkCommand.h"
|
||||
%include "vtkObject.h"
|
||||
%include "vtkDataArray.h"
|
||||
%include "vtkIdList.h"
|
||||
%include "vtkFieldData.i"
|
||||
%include "vtkDataObject.h"
|
||||
%include "vtkDataSetAttributes.i"
|
||||
%include "vtkCellData.h"
|
||||
%include "vtkPointData.h"
|
||||
%include "vtkCell.h"
|
||||
%include "vtkGenericCell.h"
|
||||
%include "vtkCellTypes.h"
|
||||
%include "vtkDataSet.h"
|
||||
%include "vtkLocator.h"
|
||||
%include "vtkPoints.h"
|
||||
%include "vtkPointLocator.h"
|
||||
%include "vtkPointSet.h"
|
||||
%include "vtkCellArray.h"
|
||||
%include "vtkCellLinks.h"
|
||||
%include "vtkProcessObject.h"
|
||||
%include "vtkSource.h"
|
||||
%include "vtkPolyData.h"
|
||||
%include "vtkPolyDataSource.h"
|
||||
%include "vtkSphereSource.h"
|
||||
%include "vtkCollection.h"
|
||||
%include "vtkImplicitFunction.h"
|
||||
%include "vtkPlane.h"
|
||||
%include "vtkPlaneCollection.h"
|
||||
%include "vtkPlanes.h"
|
||||
%include "vtkTimerLog.h"
|
||||
%include "vtkAbstractMapper.h"
|
||||
%include "vtkAbstractMapper3D.h"
|
||||
%include "vtkScalarsToColors.h"
|
||||
%include "vtkMapper.h"
|
||||
%include "vtkQuadric.h"
|
||||
%include "vtkImageSource.h"
|
||||
%include "vtkImageData.h"
|
||||
%include "vtkStructuredPoints.h"
|
||||
%include "vtkStructuredPointsSource.h"
|
||||
%include "vtkSampleFunction.h"
|
||||
%include "vtkDataSetToPolyDataFilter.h"
|
||||
%include "vtkContourValues.h"
|
||||
%include "vtkContourFilter.h"
|
||||
%include "vtkOutlineFilter.h"
|
||||
%include "vtkPolyDataMapper.h"
|
||||
%include "vtkProp.h"
|
||||
%include "vtkProp3D.h"
|
||||
%include "vtkProperty.h"
|
||||
%include "vtkTexture.h"
|
||||
%include "vtkActor.h"
|
||||
%include "vtkWindow.h"
|
||||
%include "vtkRendererCollection.h"
|
||||
%include "vtkGraphicsFactory.h"
|
||||
%include "vtkRenderWindow.h"
|
||||
%include "vtkMatrix4x4.h"
|
||||
%include "vtkLightCollection.h"
|
||||
%include "vtkPropCollection.h"
|
||||
%include "vtkVolumeCollection.h"
|
||||
%include "vtkCullerCollection.h"
|
||||
%include "vtkCamera.h"
|
||||
%include "vtkActor2D.h"
|
||||
%include "vtkViewport.h"
|
||||
%include "vtkActorCollection.h"
|
||||
%include "vtkRenderer.h"
|
||||
%include "vtkRenderWindowInteractor.h"
|
||||
|
||||
/* VTK CALLBACKS */
|
||||
|
||||
/* We want lambda procedures to be used as callbacks in VTK. To do
|
||||
this, we must create a subclass of vtkCommand and let it's Execute
|
||||
method call our Scheme lambda procedures. */
|
||||
|
||||
%{
|
||||
#include "vtkChickenCommand.h"
|
||||
vtkObject * pointerToVtkObject (C_word obj) {
|
||||
if (!C_swig_is_ptr(obj)) return 0;
|
||||
return (vtkObject*)C_pointer_address(obj);
|
||||
}
|
||||
vtkCommand* pointerToVtkCommand (C_word obj) {
|
||||
if (!C_swig_is_ptr(obj)) return 0;
|
||||
return (vtkCommand*)C_pointer_address(obj);
|
||||
}
|
||||
%}
|
||||
|
||||
%include "vtkChickenCommand.h"
|
||||
extern vtkObject * pointerToVtkObject (C_word obj);
|
||||
extern vtkCommand* pointerToVtkCommand (C_word obj);
|
||||
|
||||
%insert(chicken) {
|
||||
(define-external
|
||||
(execute_vtk_chicken_command
|
||||
(c-pointer thisCommand) ;; vtkCommand *
|
||||
(scheme-object continuation)
|
||||
(c-pointer caller) ;; vtkObject *
|
||||
(unsigned-long eventId)
|
||||
(c-pointer callData) ;; void *
|
||||
)
|
||||
void
|
||||
(continuation (+example-pointer-to-vtk-command+ thisCommand)
|
||||
(+example-pointer-to-vtk-object+ caller) eventId callData)
|
||||
)
|
||||
}
|
||||
|
||||
/* DEBUGGING CLASSES */
|
||||
|
||||
%{
|
||||
#include <iostream>
|
||||
|
||||
istream *std_cin = &cin;
|
||||
ostream *std_cout = &cout;
|
||||
ostream *std_cerr = &cerr;
|
||||
|
||||
%}
|
||||
|
||||
extern istream *std_cin;
|
||||
extern ostream *std_cout;
|
||||
extern ostream *std_cerr;
|
||||
33
SWIG/Examples/chicken/vtk/precsi.scm
Normal file
33
SWIG/Examples/chicken/vtk/precsi.scm
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
(declare (unit precsi))
|
||||
(declare (uses example))
|
||||
|
||||
(if (not (member "-quiet" (cdr (argv))))
|
||||
(begin
|
||||
;; display prelude to csi
|
||||
(display "vtk\n\n")
|
||||
|
||||
(display " A SWIG example for the CHICKEN compiler\n")
|
||||
(display " Author: Jonah Beckford, January 2003\n\n")
|
||||
|
||||
(display "C++ Classes:\n")
|
||||
(display " See http://www.vtk.org/doc/nightly/html/\n")
|
||||
|
||||
(display "\n")
|
||||
|
||||
(display "Scheme Procedures:\n")
|
||||
(display " There are way too many to document.\n")
|
||||
(display " Examples:
|
||||
vtkSphereSource::SetRadius (float radius) is
|
||||
(example-vtk-sphere-source-set-radius %sphere %radius)
|
||||
")
|
||||
|
||||
(display "\n")
|
||||
|
||||
(display "TinyCLOS Classes:\n")
|
||||
(display " There are way too many to document.\n")
|
||||
(display " Examples:
|
||||
vtkSphereSource::SetRadius (float radius) is
|
||||
(-SetRadius- %sphereObject %radius)
|
||||
")
|
||||
|
||||
(display "\n")))
|
||||
71
SWIG/Examples/chicken/vtk/test-vtk-observer.scm
Normal file
71
SWIG/Examples/chicken/vtk/test-vtk-observer.scm
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
;; run with './vtk test-vtk-sphere.scm'
|
||||
|
||||
;; All generic methods must be included first
|
||||
(include "example_generic")
|
||||
|
||||
;; After generic are defined, can include TinyCLOS code
|
||||
(include "example_clos")
|
||||
|
||||
;; -----------------
|
||||
;; Creating a sphere
|
||||
;; -----------------
|
||||
|
||||
;; create sphere geometry
|
||||
(define sphere (+example-vtk-sphere-source-new+))
|
||||
(-SetRadius- sphere 1.0)
|
||||
(-SetThetaResolution- sphere 18)
|
||||
(-SetPhiResolution- sphere 18)
|
||||
|
||||
;; create an observer
|
||||
(define printStatus
|
||||
(lambda (thisCommand caller eventId data)
|
||||
(display "Received an event!\n")
|
||||
(display "event: ")
|
||||
(display (example-vtk-command-get-string-from-event-id
|
||||
(exact->inexact eventId)))
|
||||
(display "\n")
|
||||
(display "caller: class ")
|
||||
(display (-GetClassName- caller))
|
||||
(display "\n")
|
||||
(-PrintSelf- caller (example-std-cout) (make <example-vtk-indent> 4))
|
||||
(display "data: ")
|
||||
(display data)
|
||||
(display "\n\n")))
|
||||
(define printStatusObserver (example-vtk-chicken-command-new printStatus))
|
||||
|
||||
;; attach observer to sphere's Start event
|
||||
(-AddObserver- sphere (exact->inexact (example-vtk-command-start-event))
|
||||
printStatusObserver)
|
||||
|
||||
;; map to graphics library
|
||||
(define mymap (+example-vtk-poly-data-mapper-new+))
|
||||
(-SetInput- mymap (-GetOutput- sphere))
|
||||
|
||||
;; actor coordinates geometry, properties, transformation
|
||||
(define aSphere (+example-vtk-actor-new+))
|
||||
(-SetMapper- aSphere mymap)
|
||||
(-SetColor- (-GetProperty- aSphere) 0. 0. 1.) ;; sphere color blue
|
||||
|
||||
;; a renderer and render window
|
||||
(define ren1 (+example-vtk-renderer-new+))
|
||||
(define renWin (+example-vtk-render-window-new+))
|
||||
(-AddRenderer- renWin ren1)
|
||||
|
||||
;; an interactor
|
||||
(define iren (+example-vtk-render-window-interactor-new+))
|
||||
(-SetRenderWindow- iren renWin)
|
||||
|
||||
;; attach observer to interactor's User event
|
||||
(-AddObserver- iren (exact->inexact (example-vtk-command-user-event))
|
||||
printStatusObserver)
|
||||
|
||||
;; add the actor to the scene
|
||||
(-AddActor- ren1 aSphere)
|
||||
(-SetBackground- ren1 1. 1. 1.) ;; Background color white
|
||||
|
||||
;; render an image (lights and cameras are created automatically)
|
||||
(-Render- renWin)
|
||||
|
||||
;; begin mouse interaction
|
||||
(display "Press 'u' for user event, and 'q' to quit ...\n\n")
|
||||
(-Start- iren)
|
||||
74
SWIG/Examples/chicken/vtk/test-vtk-quadric.scm
Normal file
74
SWIG/Examples/chicken/vtk/test-vtk-quadric.scm
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
;; run with './vtk test-vtk-quadric.scm'
|
||||
|
||||
;; All generic methods must be included first
|
||||
(include "example_generic")
|
||||
|
||||
;; After generic are defined, can include TinyCLOS code
|
||||
(include "example_clos")
|
||||
|
||||
;; ------------------------------
|
||||
;; Visualizing a Quadric Function
|
||||
;; ------------------------------
|
||||
|
||||
;; -- create the quadric function object --
|
||||
|
||||
;; create the quadric function definition
|
||||
(define quadric (+example-vtk-quadric-new+))
|
||||
(-SetCoefficients- quadric 0.5 1.0 0.2 0. 0.1 0. 0. 0.2 0. 0.)
|
||||
|
||||
;; sample the quadric function
|
||||
(define sample (+example-vtk-sample-function-new+))
|
||||
(-SetSampleDimensions- sample 50 50 50)
|
||||
(-SetImplicitFunction- sample quadric)
|
||||
|
||||
;; Create five surfaces F(x,y,z) = constant between range specified
|
||||
(define contours (+example-vtk-contour-filter-new+))
|
||||
(-SetInput- contours (-GetOutput- sample));
|
||||
(-GenerateValues- contours 5 0.0 1.2)
|
||||
|
||||
;; map the contours to graphical primitives
|
||||
(define contMapper (+example-vtk-poly-data-mapper-new+))
|
||||
(-SetInput- contMapper (-GetOutput- contours));
|
||||
(-SetScalarRange- contMapper 0.0 1.2)
|
||||
|
||||
;; create an actor for the contours
|
||||
(define contActor (+example-vtk-actor-new+))
|
||||
(-SetMapper- contActor contMapper)
|
||||
|
||||
;; -- create a box around the function to indicate the sampling volume --
|
||||
|
||||
;; create outline
|
||||
(define outline (+example-vtk-outline-filter-new+))
|
||||
(-SetInput- outline (-GetOutput- sample));
|
||||
|
||||
;; map it to graphics primitives
|
||||
(define outlineMapper (+example-vtk-poly-data-mapper-new+))
|
||||
(-SetInput- outlineMapper (-GetOutput- outline));
|
||||
|
||||
;; create an actor for it
|
||||
(define outlineActor (+example-vtk-actor-new+))
|
||||
(-SetMapper- outlineActor outlineMapper)
|
||||
(-SetColor- (-GetProperty- outlineActor) 0. 0. 0.)
|
||||
|
||||
;; -- render both of the objects --
|
||||
|
||||
;; a renderer and render window
|
||||
(define ren1 (+example-vtk-renderer-new+))
|
||||
(define renwin (+example-vtk-render-window-new+))
|
||||
(-AddRenderer- renwin ren1)
|
||||
|
||||
;; an interactor
|
||||
(define iren (+example-vtk-render-window-interactor-new+))
|
||||
(-SetRenderWindow- iren renwin)
|
||||
|
||||
;; add the actors to the scene
|
||||
(-AddActor- ren1 contActor)
|
||||
(-AddActor- ren1 outlineActor)
|
||||
(-SetBackground- ren1 1. 1. 1.) ;; Background color white
|
||||
|
||||
;; render an image (lights and cameras are created automatically)
|
||||
(-Render- renwin)
|
||||
|
||||
;; begin mouse interaction
|
||||
(display "Press 'q' to quit ...\n\n")
|
||||
(-Start- iren)
|
||||
46
SWIG/Examples/chicken/vtk/test-vtk-sphere.scm
Normal file
46
SWIG/Examples/chicken/vtk/test-vtk-sphere.scm
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
;; run with './vtk test-vtk-sphere.scm'
|
||||
|
||||
;; All generic methods must be included first
|
||||
(include "example_generic")
|
||||
|
||||
;; After generic are defined, can include TinyCLOS code
|
||||
(include "example_clos")
|
||||
|
||||
;; -----------------
|
||||
;; Creating a sphere
|
||||
;; -----------------
|
||||
|
||||
;; create sphere geometry
|
||||
(define sphere (+example-vtk-sphere-source-new+))
|
||||
(-SetRadius- sphere 1.0)
|
||||
(-SetThetaResolution- sphere 18)
|
||||
(-SetPhiResolution- sphere 18)
|
||||
|
||||
;; map to graphics library
|
||||
(define mymap (+example-vtk-poly-data-mapper-new+))
|
||||
(-SetInput- mymap (-GetOutput- sphere))
|
||||
|
||||
;; actor coordinates geometry, properties, transformation
|
||||
(define aSphere (+example-vtk-actor-new+))
|
||||
(-SetMapper- aSphere mymap)
|
||||
(-SetColor- (-GetProperty- aSphere) 0. 0. 1.) ;; sphere color blue
|
||||
|
||||
;; a renderer and render window
|
||||
(define ren1 (+example-vtk-renderer-new+))
|
||||
(define renWin (+example-vtk-render-window-new+))
|
||||
(-AddRenderer- renWin ren1)
|
||||
|
||||
;; an interactor
|
||||
(define iren (+example-vtk-render-window-interactor-new+))
|
||||
(-SetRenderWindow- iren renWin)
|
||||
|
||||
;; add the actor to the scene
|
||||
(-AddActor- ren1 aSphere)
|
||||
(-SetBackground- ren1 1. 1. 1.) ;; Background color white
|
||||
|
||||
;; render an image (lights and cameras are created automatically)
|
||||
(-Render- renWin)
|
||||
|
||||
;; begin mouse interaction
|
||||
(display "Press 'q' to quit ...\n\n")
|
||||
(-Start- iren)
|
||||
5056
SWIG/Examples/chicken/vtk/vtk.scm
Normal file
5056
SWIG/Examples/chicken/vtk/vtk.scm
Normal file
File diff suppressed because it is too large
Load diff
28
SWIG/Examples/chicken/vtk/vtkChickenCommand.h
Normal file
28
SWIG/Examples/chicken/vtk/vtkChickenCommand.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef __vtkChickenCommand_h
|
||||
#define __vtkChickenCommand_h
|
||||
|
||||
#include "vtkCommand.h"
|
||||
|
||||
extern "C" void
|
||||
execute_vtk_chicken_command (void *, C_word, void *, unsigned long, void *);
|
||||
|
||||
class vtkChickenCommand : public vtkCommand {
|
||||
public:
|
||||
virtual void Execute (vtkObject *caller, unsigned long eventId,
|
||||
void *callData) {
|
||||
execute_vtk_chicken_command (this, continuation, caller,
|
||||
eventId, callData);
|
||||
}
|
||||
|
||||
static vtkChickenCommand * New(C_word continuation) {
|
||||
return new vtkChickenCommand (continuation);
|
||||
}
|
||||
|
||||
protected:
|
||||
C_word continuation;
|
||||
|
||||
vtkChickenCommand (C_word continuation_) : continuation (continuation_)
|
||||
{ }
|
||||
};
|
||||
|
||||
#endif
|
||||
1
SWIG/Examples/chicken/zlib/.cvsignore
Normal file
1
SWIG/Examples/chicken/zlib/.cvsignore
Normal file
|
|
@ -0,0 +1 @@
|
|||
example_wrap.c
|
||||
62
SWIG/Examples/chicken/zlib/Makefile.in
Normal file
62
SWIG/Examples/chicken/zlib/Makefile.in
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
@SET_MAKE@
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
SOURCE_DIR = $(top_srcdir)/Examples/chicken/zlib
|
||||
TOP = ../..
|
||||
CC = @CC@
|
||||
CXX = @CXX@
|
||||
OBJEXT = @OBJEXT@
|
||||
EXEEXT = @EXEEXT@
|
||||
SWIG = $(TOP)/../swig$(EXEEXT)
|
||||
CHICKGEN = example_wrap.$(OBJEXT) csi.$(OBJEXT) precsi.$(OBJEXT) \
|
||||
oexample.$(OBJEXT)
|
||||
CHICKSRC = csi.c precsi.c oexample.c
|
||||
SRCS = $(CHICKGEN)
|
||||
TARGET = zlib$(EXEEXT)
|
||||
INCLUDE = -I$(SOURCE_DIR)
|
||||
LIBS = -lz
|
||||
SWIGOPT = -prefix zlib -mixed -I/usr/include
|
||||
|
||||
all:: $(TARGET)
|
||||
|
||||
.SUFFIXES: .cxx
|
||||
|
||||
.c.o:
|
||||
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
.cxx.o:
|
||||
$(CXX) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
csi.c:
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='csi.c' \
|
||||
INTERFACE='precsi' chicken_csi
|
||||
|
||||
precsi.c: $(SOURCE_DIR)/precsi.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='precsi.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
example_wrap.c example.scm: $(SOURCE_DIR)/example.i
|
||||
(test $< -nt example.i && cp -p $< example.i) || echo example.i is up-to-date
|
||||
$(MAKE) -f $(TOP)/Makefile SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT)' \
|
||||
INCLUDE='$(INCLUDE)' INTERFACE='example.i' chicken_c || \
|
||||
(echo Did you read the README? && exit 1)
|
||||
|
||||
oexample.c: example.scm
|
||||
$(MAKE) -f $(TOP)/Makefile TARGET='oexample.c' \
|
||||
INTERFACE='$<' chicken
|
||||
|
||||
$(TARGET): $(SRCS)
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \
|
||||
LIBS='$(LIBS)' INTERFACE='$(INTERFACE)' chicken_static || \
|
||||
(echo Did you read the README? && exit 1)
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.$(OBJEXT) core *~ *.so *.stackdump STACKTRACE
|
||||
rm -f $(CHICKGEN) $(CHICKSRC)
|
||||
rm -f example.scm
|
||||
rm -f $(TARGET)
|
||||
|
||||
check:
|
||||
1674
SWIG/Examples/chicken/zlib/README.html
Normal file
1674
SWIG/Examples/chicken/zlib/README.html
Normal file
File diff suppressed because it is too large
Load diff
84
SWIG/Examples/chicken/zlib/example.i
Normal file
84
SWIG/Examples/chicken/zlib/example.i
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%{
|
||||
/* Put headers and other declarations here */
|
||||
#include "zlib.h"
|
||||
%}
|
||||
|
||||
%include typemaps.i
|
||||
|
||||
%rename(VERSION) ZLIB_VERSION;
|
||||
%rename(z_error) zError;
|
||||
%apply char * { Bytef * };
|
||||
|
||||
/* Allow the sourceLen to be automatically filled in from the length
|
||||
of the 'source' string */
|
||||
%typemap(chicken,in) (const Bytef *source, uLong sourceLen)
|
||||
%{ if (!C_swig_is_string ($input)) {
|
||||
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument $input is not a string");
|
||||
}
|
||||
$2 = (uLong) C_header_size ($input);
|
||||
$1 = C_c_string ($input);
|
||||
%}
|
||||
|
||||
/* Allocate space the size of which is determined by the Scheme
|
||||
integer argument, and make a temporary integer so we can set
|
||||
destLen. */
|
||||
%typemap(chicken,in) (Bytef *dest, uLongf *destLen) (uLong len)
|
||||
%{ if (!C_swig_is_fixnum ($input)) {
|
||||
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, "Argument $input is not a integer");
|
||||
}
|
||||
len = (uLong) C_unfix ($input);
|
||||
$2 = &len;
|
||||
$1 = (char *) malloc (*$2);
|
||||
%}
|
||||
|
||||
/* Return the mutated string as a new object. Notice the if MANY construct ... they must be at column 0. */
|
||||
%typemap(chicken,argout,fragment="list_output_helper",chicken_words="0") (Bytef *dest, uLongf *destLen)
|
||||
(C_word *scmstr)
|
||||
%{ scmstr = C_alloc (C_SIZEOF_STRING (*$2));
|
||||
/*if MANY*/
|
||||
$result = list_output_helper (&known_space, $result, C_string (&scmstr, *$2, $1));
|
||||
/*else*/
|
||||
$result = C_string (&scmstr, *$2, $1);
|
||||
/*endif*/
|
||||
free ($1);
|
||||
%}
|
||||
|
||||
%include "zconf.h"
|
||||
%include "zlib.h"
|
||||
|
||||
/* Ignore destLen as an input argument, and make a temporary integer so
|
||||
we can set destLen. */
|
||||
%typemap(in, numinputs=0) uLongf *destLen (uLong len)
|
||||
"$1 = &len;";
|
||||
|
||||
/* Return a sized string as a new object. */
|
||||
%typemap(chicken,argout,fragment="list_output_helper",chicken_words="0")
|
||||
(void *outstr, uLongf *destLen) (C_word *scmstr)
|
||||
%{ scmstr = C_alloc (C_SIZEOF_STRING (*$2));
|
||||
/*if MANY*/
|
||||
$result = list_output_helper (&known_space, $result, C_string (&scmstr, *$2, $1));
|
||||
/*else*/
|
||||
$result = C_string (&scmstr, *$2, $1);
|
||||
/*endif*/
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
/* %inline blocks are seen by SWIG and are inserted into the header
|
||||
portion of example_wrap.c, so that they are also seen by the C
|
||||
compiler. */
|
||||
int deflate_init(z_streamp strm, int level) {
|
||||
return deflateInit(strm,level); /* call macro */
|
||||
}
|
||||
int inflate_init(z_streamp strm) {
|
||||
return inflateInit(strm); /* call macro */
|
||||
}
|
||||
void* z_stream_save_next_out(z_streamp strm) {
|
||||
return (void*) strm->next_out;
|
||||
}
|
||||
void z_stream_get_next_chunk(z_streamp strm, void *outstr, uLongf *destLen) {
|
||||
*destLen = strm->next_out - (Bytef*)outstr;
|
||||
}
|
||||
%}
|
||||
|
||||
123
SWIG/Examples/chicken/zlib/precsi.scm
Normal file
123
SWIG/Examples/chicken/zlib/precsi.scm
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
(declare (unit precsi))
|
||||
(declare (uses example))
|
||||
|
||||
;; display prelude to csi
|
||||
(display "zlib\n\n")
|
||||
|
||||
(display " A SWIG example for the CHICKEN compiler\n")
|
||||
(display " Author: Jonah Beckford, February 2003\n\n")
|
||||
|
||||
(display "Scheme Procedures:\n")
|
||||
(display "
|
||||
zlib-max-mem-level
|
||||
zlib-max-wbits
|
||||
zlib-seek-set
|
||||
zlib-seek-cur
|
||||
zlib-seek-end
|
||||
zlib-version
|
||||
zlib-z-stream-next-in-set
|
||||
zlib-z-stream-next-in-get
|
||||
zlib-z-stream-avail-in-set
|
||||
zlib-z-stream-avail-in-get
|
||||
zlib-z-stream-total-in-set
|
||||
zlib-z-stream-total-in-get
|
||||
zlib-z-stream-next-out-set
|
||||
zlib-z-stream-next-out-get
|
||||
zlib-z-stream-avail-out-set
|
||||
zlib-z-stream-avail-out-get
|
||||
zlib-z-stream-total-out-set
|
||||
zlib-z-stream-total-out-get
|
||||
zlib-z-stream-msg-set
|
||||
zlib-z-stream-msg-get
|
||||
zlib-z-stream-state-set
|
||||
zlib-z-stream-state-get
|
||||
zlib-z-stream-zalloc-set
|
||||
zlib-z-stream-zalloc-get
|
||||
zlib-z-stream-zfree-set
|
||||
zlib-z-stream-zfree-get
|
||||
zlib-z-stream-opaque-set
|
||||
zlib-z-stream-opaque-get
|
||||
zlib-z-stream-data-type-set
|
||||
zlib-z-stream-data-type-get
|
||||
zlib-z-stream-adler-set
|
||||
zlib-z-stream-adler-get
|
||||
zlib-z-stream-reserved-set
|
||||
zlib-z-stream-reserved-get
|
||||
zlib-new-z-stream
|
||||
zlib-delete-z-stream
|
||||
zlib-z-no-flush
|
||||
zlib-z-partial-flush
|
||||
zlib-z-sync-flush
|
||||
zlib-z-full-flush
|
||||
zlib-z-finish
|
||||
zlib-z-ok
|
||||
zlib-z-stream-end
|
||||
zlib-z-need-dict
|
||||
zlib-z-errno
|
||||
zlib-z-stream-error
|
||||
zlib-z-data-error
|
||||
zlib-z-mem-error
|
||||
zlib-z-buf-error
|
||||
zlib-z-version-error
|
||||
zlib-z-no-compression
|
||||
zlib-z-best-speed
|
||||
zlib-z-best-compression
|
||||
zlib-z-default-compression
|
||||
zlib-z-filtered
|
||||
zlib-z-huffman-only
|
||||
zlib-z-default-strategy
|
||||
zlib-z-binary
|
||||
zlib-z-ascii
|
||||
zlib-z-unknown
|
||||
zlib-z-deflated
|
||||
zlib-z-null
|
||||
zlib-version
|
||||
zlib-deflate
|
||||
zlib-deflate-end
|
||||
zlib-inflate
|
||||
zlib-inflate-end
|
||||
zlib-deflate-set-dictionary
|
||||
zlib-deflate-copy
|
||||
zlib-deflate-reset
|
||||
zlib-deflate-params
|
||||
zlib-inflate-set-dictionary
|
||||
zlib-inflate-sync
|
||||
zlib-inflate-reset
|
||||
zlib-compress
|
||||
zlib-compress2
|
||||
zlib-uncompress
|
||||
zlib-gzopen
|
||||
zlib-gzdopen
|
||||
zlib-gzsetparams
|
||||
zlib-gzread
|
||||
zlib-gzwrite
|
||||
zlib-gzprintf
|
||||
zlib-gzputs
|
||||
zlib-gzgets
|
||||
zlib-gzputc
|
||||
zlib-gzgetc
|
||||
zlib-gzflush
|
||||
zlib-gzseek
|
||||
zlib-gzrewind
|
||||
zlib-gztell
|
||||
zlib-gzeof
|
||||
zlib-gzclose
|
||||
zlib-gzerror
|
||||
zlib-adler32
|
||||
zlib-crc32
|
||||
zlib-deflate-init-
|
||||
zlib-inflate-init-
|
||||
zlib-deflate-init2-
|
||||
zlib-inflate-init2-
|
||||
zlib-internal-state-dummy-set
|
||||
zlib-internal-state-dummy-get
|
||||
zlib-new-internal-state
|
||||
zlib-delete-internal-state
|
||||
zlib-z-error
|
||||
zlib-inflate-sync-point
|
||||
zlib-get-crc-table
|
||||
zlib-deflate-init
|
||||
zlib-inflate-init
|
||||
zlib-z-stream-save-next-out
|
||||
zlib-z-stream-get-next-chunk
|
||||
")
|
||||
42
SWIG/Examples/chicken/zlib/test-zlib.scm
Normal file
42
SWIG/Examples/chicken/zlib/test-zlib.scm
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
;; run with './zlib test-zlib.scm'
|
||||
|
||||
;; Init zstream
|
||||
(define s (zlib-new-z-stream))
|
||||
(zlib-z-stream-zalloc-set s #f)
|
||||
(zlib-z-stream-zfree-set s #f)
|
||||
(zlib-z-stream-opaque-set s #f)
|
||||
(zlib-deflate-init s (zlib-z-default-compression))
|
||||
|
||||
;; Deflate something small so we don't need to loop/stream data
|
||||
(define in "some pony et jumping et jack et flash et had a jack pony")
|
||||
(define out (make-string 1000))
|
||||
(format #t "to be compressed: ~A~%to be compressed bytes: ~D~%~%" in (string-length in))
|
||||
(zlib-z-stream-next-in-set s in)
|
||||
(zlib-z-stream-avail-in-set s (string-length in))
|
||||
(zlib-z-stream-next-out-set s out)
|
||||
(zlib-z-stream-avail-out-set s (string-length out))
|
||||
(let*
|
||||
((saved-out (zlib-z-stream-save-next-out s))
|
||||
(ret (zlib-deflate s (zlib-z-finish))))
|
||||
(cond
|
||||
((= ret (zlib-z-stream-end))
|
||||
(format #t "deflated properly!~%compressed bytes: ~D~%compressed stream: ~S~%"
|
||||
(zlib-z-stream-total-out-get s) (zlib-z-stream-get-next-chunk s saved-out)))
|
||||
((= ret (zlib-z-ok))
|
||||
(display "only partial deflation ... not enough output space\n"))
|
||||
(else
|
||||
(format #t "deflate error(~D): ~A ~%" ret (zlib-z-stream-msg-get s)))))
|
||||
|
||||
;; Use simple compress routine, and set max output size to 100
|
||||
(define c (zlib-compress 100 in))
|
||||
(newline)
|
||||
(let
|
||||
((ret (car c))
|
||||
(compressed (cadr c)))
|
||||
(cond
|
||||
((= ret (zlib-z-ok))
|
||||
(format #t "compressed properly!~%compressed bytes: ~D~%compressed stream: ~S~%"
|
||||
(string-length compressed) compressed))
|
||||
(else
|
||||
(format #t "compress error(~D): ~A ~%" ret (zlib-z-error ret)))))
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue