Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
SRCS = example.c
include $(SRCDIR)../example.mk

View 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;

View File

@@ -0,0 +1,8 @@
/* 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);

View File

@@ -0,0 +1,18 @@
/* File : example.i */
%module swigexample
%feature("autodoc", 1);
%{
#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);

View File

@@ -0,0 +1,23 @@
# do not dump Octave core
if exist("crash_dumps_octave_core", "builtin")
crash_dumps_octave_core(0);
endif
swigexample
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", swigexample.do_op(a,b,swigexample.ADD));
printf(" SUB(a,b) = %i\n", swigexample.do_op(a,b,swigexample.SUB));
printf(" MUL(a,b) = %i\n", swigexample.do_op(a,b,swigexample.MUL));
printf("Here is what the C callback function objects look like in Octave\n");
swigexample.ADD
swigexample.SUB
swigexample.MUL