diff options
Diffstat (limited to 'Examples/chicken/overload')
| -rw-r--r-- | Examples/chicken/overload/Makefile | 30 | ||||
| -rw-r--r-- | Examples/chicken/overload/README | 2 | ||||
| -rw-r--r-- | Examples/chicken/overload/example.cxx | 33 | ||||
| -rw-r--r-- | Examples/chicken/overload/example.h | 14 | ||||
| -rw-r--r-- | Examples/chicken/overload/example.i | 16 | ||||
| -rw-r--r-- | Examples/chicken/overload/test-overload.scm | 45 |
6 files changed, 140 insertions, 0 deletions
diff --git a/Examples/chicken/overload/Makefile b/Examples/chicken/overload/Makefile new file mode 100644 index 0000000..48ec43a --- /dev/null +++ b/Examples/chicken/overload/Makefile @@ -0,0 +1,30 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +INTERFACE = example.i +SRCS = +CXXSRCS = example.cxx +TARGET = overload +INCLUDE = +SWIGOPT = -proxy -unhideprimitive +CFLAGS = +VARIANT = + +# uncomment the following lines to build a static exe +#CHICKEN_MAIN = test-overload.scm +#VARIANT = _static + +all:: $(TARGET) + +$(TARGET): $(INTERFACE) $(SRCS) + $(MAKE) -f $(TOP)/Makefile \ + SRCS='$(SRCS)' CXXSRCS='$(CXXSRCS)' CHICKEN_MAIN='$(CHICKEN_MAIN)' \ + INCLUDE='$(INCLUDE)' SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' \ + SWIG='$(SWIG)' INTERFACE='$(INTERFACE)' CHICKENOPTS='$(CHICKENOPTS)' chicken$(VARIANT)_cpp + +clean:: + $(MAKE) -f $(TOP)/Makefile chicken_clean + rm -f example.scm + rm -f $(TARGET) + +check:: + env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH csi test-overload.scm diff --git a/Examples/chicken/overload/README b/Examples/chicken/overload/README new file mode 100644 index 0000000..9487c3f --- /dev/null +++ b/Examples/chicken/overload/README @@ -0,0 +1,2 @@ +Overloading example from Chapter 5.14 of SWIG Core Documentation for +version 1.3. diff --git a/Examples/chicken/overload/example.cxx b/Examples/chicken/overload/example.cxx new file mode 100644 index 0000000..65e7439 --- /dev/null +++ b/Examples/chicken/overload/example.cxx @@ -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); +} diff --git a/Examples/chicken/overload/example.h b/Examples/chicken/overload/example.h new file mode 100644 index 0000000..1c135d5 --- /dev/null +++ b/Examples/chicken/overload/example.h @@ -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); +}; diff --git a/Examples/chicken/overload/example.i b/Examples/chicken/overload/example.i new file mode 100644 index 0000000..23a2998 --- /dev/null +++ b/Examples/chicken/overload/example.i @@ -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" + diff --git a/Examples/chicken/overload/test-overload.scm b/Examples/chicken/overload/test-overload.scm new file mode 100644 index 0000000..168490f --- /dev/null +++ b/Examples/chicken/overload/test-overload.scm @@ -0,0 +1,45 @@ +;; This file demonstrates the overloading capabilities of SWIG + +(load-library 'example "overload.so") + +;; Low level +;; --------- + +(display " +Trying low level code ... + (foo 1) + (foo \"some string\") + (define A-FOO (new-Foo)) + (define ANOTHER-FOO (new-Foo A-FOO)) ;; copy constructor + (Foo-bar A-FOO 2) + (Foo-bar ANOTHER-FOO \"another string\" 3) +") + +(primitive:foo 1) +(primitive:foo "some string") +(define A-FOO (slot-ref (primitive:new-Foo) 'swig-this)) +(define ANOTHER-FOO (slot-ref (primitive:new-Foo A-FOO) 'swig-this)) ;; copy constructor +(primitive:Foo-bar A-FOO 2) +(primitive:Foo-bar ANOTHER-FOO "another string" 3) + +;; TinyCLOS +;; -------- + +(display " +Trying TinyCLOS code ... + (+foo+ 1) + (+foo+ \"some string\") + (define A-FOO (make <Foo>)) + (define ANOTHER-FOO (make <Foo> A-FOO)) ;; copy constructor + (-bar- A-FOO 2) + (-bar- ANOTHER-FOO \"another string\" 3) +") + +(foo 1) +(foo "some string") +(define A-FOO (make <Foo>)) +(define ANOTHER-FOO (make <Foo> A-FOO)) ;; copy constructor +(bar A-FOO 2) +(bar ANOTHER-FOO "another string" 3) + +(exit) |
