update swig on windows

This commit is contained in:
Bassem Girgis
2019-08-04 21:38:19 -05:00
parent 8414b7136b
commit 76ad52be58
5943 changed files with 91790 additions and 71892 deletions

View File

@@ -0,0 +1 @@
include ../example.mk

View File

@@ -0,0 +1,42 @@
module runme;
import tango.io.Stdout;
static import example;
extern(C) int add(int a, int b) {
return a + b;
}
extern(C) int sub(int a, int b) {
return a - b;
}
extern(C) int mul(int a, int b) {
return a * b;
}
void main() {
int a = 37;
int b = 42;
Stdout( "a = " )( a ).newline;
Stdout( "b = " )( b ).newline;
Stdout( "Trying some C callback functions:" ).newline;
Stdout( " ADD(a,b) = " )( example.do_op( a, b, example.ADD ) ).newline;
Stdout( " SUB(a,b) = " )( example.do_op( a, b, example.SUB ) ).newline;
Stdout( " MUL(a,b) = " )( example.do_op( a, b, example.MUL ) ).newline;
version (LDC) {
// Currently, there is no way to specify the calling convention for
// function pointer parameters in D, but LDC does strict typechecking for
// them (which is reasonable, but not covered by the language spec yet).
// As a result, there is no way to make the code below compile with LDC at
// the moment, so just skip it.
} else {
Stdout( "Now the same with callback functions defined in D:" ).newline;
Stdout( " add(a,b) = " )( example.do_op( a, b, &add ) ).newline;
Stdout( " sub(a,b) = " )( example.do_op( a, b, &sub ) ).newline;
Stdout( " mul(a,b) = " )( example.do_op( a, b, &mul ) ).newline;
}
}

View File

@@ -0,0 +1,34 @@
module runme;
import std.stdio;
static import example;
extern(C) int add(int a, int b) {
return a + b;
}
extern(C) int sub(int a, int b) {
return a - b;
}
extern(C) int mul(int a, int b) {
return a * b;
}
void main() {
int a = 37;
int b = 42;
writefln( "a = %s", a );
writefln( "b = %s", b );
writeln( "Trying some C callback functions:" );
writefln( " ADD(a,b) = %s", example.do_op( a, b, example.ADD ) );
writefln( " SUB(a,b) = %s", example.do_op( a, b, example.SUB ) );
writefln( " MUL(a,b) = %s", example.do_op( a, b, example.MUL ) );
writeln( "Now the same with callback functions defined in D:" );
writefln( " add(a,b) = %s", example.do_op( a, b, &add ) );
writefln( " sub(a,b) = %s", example.do_op( a, b, &sub ) );
writefln( " mul(a,b) = %s", example.do_op( a, b, &mul ) );
}

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,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);

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