diff --git a/work-in-progress/cffi/examples/simple/cpp/.gitignore b/work-in-progress/cffi/examples/simple/cpp/.gitignore new file mode 100644 index 0000000..1f45a09 --- /dev/null +++ b/work-in-progress/cffi/examples/simple/cpp/.gitignore @@ -0,0 +1,2 @@ +ndll +obj diff --git a/work-in-progress/cffi/examples/simple/cpp/Build.xml b/work-in-progress/cffi/examples/simple/cpp/Build.xml new file mode 100644 index 0000000..ac31e60 --- /dev/null +++ b/work-in-progress/cffi/examples/simple/cpp/Build.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + +
+ +
+ +
+ + +
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/work-in-progress/cffi/examples/simple/cpp/Foreign.cpp b/work-in-progress/cffi/examples/simple/cpp/Foreign.cpp new file mode 100644 index 0000000..2b68dfe --- /dev/null +++ b/work-in-progress/cffi/examples/simple/cpp/Foreign.cpp @@ -0,0 +1,17 @@ +#define IMPLEMENT_API +#include + +extern "C" +{ + + value CPP_ForeignFunction(value haxeVal) + { + int intVal = val_int(haxeVal); + printf("CPP: intVal = %d\n",intVal); + intVal++; + value returnVal = alloc_int(intVal); + return returnVal; + } + DEFINE_PRIM(CPP_ForeignFunction, 1); + +} diff --git a/work-in-progress/cffi/examples/simple/cpp/README.md b/work-in-progress/cffi/examples/simple/cpp/README.md new file mode 100644 index 0000000..fa82abe --- /dev/null +++ b/work-in-progress/cffi/examples/simple/cpp/README.md @@ -0,0 +1,9 @@ +Use hxcpp (invoked with haxelib) and a `Build.xml` file to define a +cross-platform build. Run the build with: + +``` +haxelib run hxcpp Build.xml +``` + +This is a cross-platform way to invoke the C++ compiler with all the options +necessary to build the `libforeign.ndll` library. diff --git a/work-in-progress/cffi/examples/simple/hx/.gitignore b/work-in-progress/cffi/examples/simple/hx/.gitignore new file mode 100644 index 0000000..1fcb152 --- /dev/null +++ b/work-in-progress/cffi/examples/simple/hx/.gitignore @@ -0,0 +1 @@ +out diff --git a/work-in-progress/cffi/examples/simple/hx/Main.hx b/work-in-progress/cffi/examples/simple/hx/Main.hx new file mode 100644 index 0000000..bd14601 --- /dev/null +++ b/work-in-progress/cffi/examples/simple/hx/Main.hx @@ -0,0 +1,21 @@ +import cpp.Lib; + +class Main +{ + public var ForeignFunction:Dynamic; + public function new() + { + trace("Hello from Main, about to load libforeign library"); + try { + ForeignFunction = cpp.Lib.load("libforeign", "CPP_ForeignFunction",1); + } catch (e:Dynamic) { + trace("Failed to load libforeign.ndll!"); + return; + } + + var a:Int = ForeignFunction(2); + trace("Main called ForeignFunction(2), returned "+a); + } + + public static function main() { new Main(); } +} diff --git a/work-in-progress/cffi/examples/simple/hx/build.hxml b/work-in-progress/cffi/examples/simple/hx/build.hxml new file mode 100644 index 0000000..19426e3 --- /dev/null +++ b/work-in-progress/cffi/examples/simple/hx/build.hxml @@ -0,0 +1,5 @@ +-main Main.hx +-cpp out + +# Runtime needs the ndll +-cmd cp ../cpp/ndll/Linux64/libforeign.ndll out