Initial commit of Octave module.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10290 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
50b1578e19
commit
393391965c
275 changed files with 14004 additions and 5 deletions
21
Examples/octave/funcptr/Makefile
Normal file
21
Examples/octave/funcptr/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS = -lm
|
||||
SWIGOPT =
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave_cpp
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_cpp_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
rm -f $(TARGET).py
|
||||
|
||||
check: all
|
||||
19
Examples/octave/funcptr/example.c
Normal file
19
Examples/octave/funcptr/example.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/* 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;
|
||||
}
|
||||
|
||||
int (*funcvar)(int,int) = add;
|
||||
9
Examples/octave/funcptr/example.h
Normal file
9
Examples/octave/funcptr/example.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/* file: example.h */
|
||||
|
||||
extern int do_op(int,int, int (*op)(int,int));
|
||||
extern int add(int,int);
|
||||
extern int sub(int,int);
|
||||
extern int mul(int,int);
|
||||
|
||||
extern int (*funcvar)(int,int);
|
||||
|
||||
16
Examples/octave/funcptr/example.i
Normal file
16
Examples/octave/funcptr/example.i
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* Wrap a function taking a pointer to a function */
|
||||
extern int do_op(int a, int b, int (*op)(int, int));
|
||||
|
||||
/* Now install a bunch of "ops" as constants */
|
||||
%constant int (*ADD)(int,int) = add;
|
||||
%constant int (*SUB)(int,int) = sub;
|
||||
%constant int (*MUL)(int,int) = mul;
|
||||
|
||||
extern int (*funcvar)(int,int);
|
||||
|
||||
21
Examples/octave/funcptr/runme.m
Normal file
21
Examples/octave/funcptr/runme.m
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# file: runme.m
|
||||
|
||||
example
|
||||
|
||||
a = 37
|
||||
b = 42
|
||||
|
||||
# Now call our C function with a bunch of callbacks
|
||||
|
||||
printf("Trying some C callback functions\n");
|
||||
printf(" a = %i\n", a);
|
||||
printf(" b = %i\n", b);
|
||||
printf(" ADD(a,b) = %i\n", example.do_op(a,b,example.ADD));
|
||||
printf(" SUB(a,b) = %i\n", example.do_op(a,b,example.SUB));
|
||||
printf(" MUL(a,b) = %i\n", example.do_op(a,b,example.MUL));
|
||||
|
||||
printf("Here is what the C callback function objects look like in Octave\n");
|
||||
example.ADD
|
||||
example.SUB
|
||||
example.MUL
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue