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
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue