diff --git a/SWIG/Examples/python/class/example.h b/SWIG/Examples/python/class/example.h index 849071dd3..b01e8bb0a 100644 --- a/SWIG/Examples/python/class/example.h +++ b/SWIG/Examples/python/class/example.h @@ -9,9 +9,11 @@ public: nshapes--; }; double x, y; + char foo[256]; void move(double dx, double dy); virtual double area() = 0; virtual double perimeter() = 0; + char *name() { return "Shape"; } static int nshapes; }; @@ -24,6 +26,13 @@ public: virtual double perimeter(); }; +class XCircle : public Circle { + public: + XCircle(double r) : Circle(r) { }; + virtual double area(); + char *name() { return "XCircle"; } +}; + class Square : public Shape { private: double width; diff --git a/SWIG/Examples/python/class/example.i b/SWIG/Examples/python/class/example.i index 23ee8a822..3cd206c26 100644 --- a/SWIG/Examples/python/class/example.i +++ b/SWIG/Examples/python/class/example.i @@ -6,6 +6,9 @@ %} /* Let's just grab the original header file here */ +%typemap(memberin) char [ANY] { + strncpy($target,$source,$dim0); +} %include "example.h" diff --git a/SWIG/Examples/python/funcptr/Makefile b/SWIG/Examples/python/funcptr/Makefile new file mode 100644 index 000000000..e495cfa9a --- /dev/null +++ b/SWIG/Examples/python/funcptr/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../swig +SRCS = example.c +TARGET = example +INTERFACE = example.i + +all:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python + +static:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='mypython' INTERFACE='$(INTERFACE)' python_static + +clean:: + rm -f *_wrap* *.o *~ *.so mypython *.pyc .~* core + +check: all diff --git a/SWIG/Examples/python/funcptr/example.c b/SWIG/Examples/python/funcptr/example.c new file mode 100644 index 000000000..99583b72e --- /dev/null +++ b/SWIG/Examples/python/funcptr/example.c @@ -0,0 +1,17 @@ +/* File : example.c */ + +int do_op(int a, int b, int (*op)(int,int)) { + return (*op)(a,b); +} + +int add(int a, int b) { + return a+b; +} + +int sub(int a, int b) { + return a-b; +} + +int mul(int a, int b) { + return a*b; +} diff --git a/SWIG/Examples/python/index.html b/SWIG/Examples/python/index.html index c11247421..fcf607895 100644 --- a/SWIG/Examples/python/index.html +++ b/SWIG/Examples/python/index.html @@ -21,6 +21,7 @@ certain C declarations are turned into constants.