From 2824b0cbb66e715490e1ef13250bd675d87b32d9 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Wed, 2 Jun 2010 20:53:17 +0000 Subject: rel-2.0.0 git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/tags/rel-2.0.0@12089 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- trunk/Examples/csharp/funcptr/Makefile | 20 +++ trunk/Examples/csharp/funcptr/example-cs.csproj | 94 ++++++++++++++ trunk/Examples/csharp/funcptr/example-vc.vcproj | 160 ++++++++++++++++++++++++ trunk/Examples/csharp/funcptr/example.c | 19 +++ trunk/Examples/csharp/funcptr/example.h | 9 ++ trunk/Examples/csharp/funcptr/example.i | 16 +++ trunk/Examples/csharp/funcptr/example.sln | 30 +++++ trunk/Examples/csharp/funcptr/runme.cs | 27 ++++ 8 files changed, 375 insertions(+) create mode 100644 trunk/Examples/csharp/funcptr/Makefile create mode 100644 trunk/Examples/csharp/funcptr/example-cs.csproj create mode 100644 trunk/Examples/csharp/funcptr/example-vc.vcproj create mode 100644 trunk/Examples/csharp/funcptr/example.c create mode 100644 trunk/Examples/csharp/funcptr/example.h create mode 100644 trunk/Examples/csharp/funcptr/example.i create mode 100644 trunk/Examples/csharp/funcptr/example.sln create mode 100644 trunk/Examples/csharp/funcptr/runme.cs (limited to 'trunk/Examples/csharp/funcptr') diff --git a/trunk/Examples/csharp/funcptr/Makefile b/trunk/Examples/csharp/funcptr/Makefile new file mode 100644 index 000000000..223300497 --- /dev/null +++ b/trunk/Examples/csharp/funcptr/Makefile @@ -0,0 +1,20 @@ +TOP = ../.. +SWIG = $(TOP)/../preinst-swig +SRCS = example.c +TARGET = example +INTERFACE = example.i +SWIGOPT = +CSHARPSRCS = *.cs +CSHARPFLAGS= -nologo -out:runme.exe + +all:: csharp + +csharp:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp + $(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile + +clean:: + $(MAKE) -f $(TOP)/Makefile csharp_clean + +check: all diff --git a/trunk/Examples/csharp/funcptr/example-cs.csproj b/trunk/Examples/csharp/funcptr/example-cs.csproj new file mode 100644 index 000000000..5ff0d9da9 --- /dev/null +++ b/trunk/Examples/csharp/funcptr/example-cs.csproj @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/trunk/Examples/csharp/funcptr/example-vc.vcproj b/trunk/Examples/csharp/funcptr/example-vc.vcproj new file mode 100644 index 000000000..03047bfb0 --- /dev/null +++ b/trunk/Examples/csharp/funcptr/example-vc.vcproj @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/trunk/Examples/csharp/funcptr/example.c b/trunk/Examples/csharp/funcptr/example.c new file mode 100644 index 000000000..5c4a3dabf --- /dev/null +++ b/trunk/Examples/csharp/funcptr/example.c @@ -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; diff --git a/trunk/Examples/csharp/funcptr/example.h b/trunk/Examples/csharp/funcptr/example.h new file mode 100644 index 000000000..9936e24fc --- /dev/null +++ b/trunk/Examples/csharp/funcptr/example.h @@ -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); + diff --git a/trunk/Examples/csharp/funcptr/example.i b/trunk/Examples/csharp/funcptr/example.i new file mode 100644 index 000000000..8b3bef678 --- /dev/null +++ b/trunk/Examples/csharp/funcptr/example.i @@ -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); + diff --git a/trunk/Examples/csharp/funcptr/example.sln b/trunk/Examples/csharp/funcptr/example.sln new file mode 100644 index 000000000..28b9851b0 --- /dev/null +++ b/trunk/Examples/csharp/funcptr/example.sln @@ -0,0 +1,30 @@ +Microsoft Visual Studio Solution File, Format Version 8.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}" + ProjectSection(ProjectDependencies) = postProject + {C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + Debug = Debug + Release = Release + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET + {C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32 + {C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/trunk/Examples/csharp/funcptr/runme.cs b/trunk/Examples/csharp/funcptr/runme.cs new file mode 100644 index 000000000..ba2e228ea --- /dev/null +++ b/trunk/Examples/csharp/funcptr/runme.cs @@ -0,0 +1,27 @@ + +using System; +using System.Reflection; + +public class runme { + + public static void Main(String[] args) { + + + int a = 37; + int b = 42; + + // Now call our C function with a bunch of callbacks + + Console.WriteLine( "Trying some C callback functions" ); + Console.WriteLine( " a = " + a ); + Console.WriteLine( " b = " + b ); + Console.WriteLine( " ADD(a,b) = " + example.do_op(a,b,example.ADD) ); + Console.WriteLine( " SUB(a,b) = " + example.do_op(a,b,example.SUB) ); + Console.WriteLine( " MUL(a,b) = " + example.do_op(a,b,example.MUL) ); + + Console.WriteLine( "Here is what the C callback function classes are called in C#" ); + Console.WriteLine( " ADD = " + example.ADD.GetType() ); + Console.WriteLine( " SUB = " + example.SUB.GetType() ); + Console.WriteLine( " MUL = " + example.MUL.GetType() ); + } +} -- cgit v1.2.1