add array example
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11478 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
8217f59d55
commit
a19aea6b4b
16 changed files with 456 additions and 240 deletions
17
Examples/scilab/funcptr/Makefile
Normal file
17
Examples/scilab/funcptr/Makefile
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab
|
||||
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile scilab_clean
|
||||
rm -f *.sce *.so lib*lib.c *_wrap.c
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile scilab_run
|
||||
20
Examples/scilab/funcptr/example.c
Normal file
20
Examples/scilab/funcptr/example.c
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* 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/scilab/funcptr/example.h
Normal file
9
Examples/scilab/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);
|
||||
|
||||
11
Examples/scilab/funcptr/example.i
Normal file
11
Examples/scilab/funcptr/example.i
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/* 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));
|
||||
|
||||
extern int (*funcvar)(int,int);
|
||||
|
||||
20
Examples/scilab/funcptr/runme.sci
Normal file
20
Examples/scilab/funcptr/runme.sci
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// builder the *.so
|
||||
exec builder.sce;
|
||||
|
||||
// loader the *.so
|
||||
exec loader.sce;
|
||||
|
||||
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", do_op(a,b,funcvar_get()));
|
||||
|
||||
exit
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue