diff --git a/include/cpp/Pointer.h b/include/cpp/Pointer.h index 95564ed88..74a68ee35 100644 --- a/include/cpp/Pointer.h +++ b/include/cpp/Pointer.h @@ -426,6 +426,12 @@ class Function public: T *call; + #ifdef HXCPP_GC_GENERATIONAL + // Haxe versions without HaxeFoundation/haxe#13002 write barrier cpp.Function + // fields as objects. A null mPtr turns those barriers into no-ops. + static constexpr hx::Object *mPtr = 0; + #endif + inline Function( ) { } inline Function( const Function &inRHS ) : call(inRHS.call) { } inline Function( const Dynamic &inRHS) { call = inRHS==null()?0: (T*)inRHS->__GetHandle(); } diff --git a/test/haxe/TestTypes.hx b/test/haxe/TestTypes.hx index 55075a889..cce4b8ba6 100644 --- a/test/haxe/TestTypes.hx +++ b/test/haxe/TestTypes.hx @@ -12,6 +12,7 @@ class TestTypes extends Test var i6:cpp.UInt8 = 1; var i7:cpp.Int16 = 1; var i8:cpp.UInt16 = 1; + var callback:cpp.FunctionInt, cpp.abi.Abi>; public function new() super(); @@ -49,4 +50,15 @@ class TestTypes extends Test Assert.equals(d.i6, 1); Assert.equals(d.i7, 1); } + + static function increment(value:Int):Int + { + return value + 1; + } + + public function testFunctionField() + { + callback = cpp.Function.fromStaticFunction(increment); + Assert.equals(callback.call(41), 42); + } }