Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/cpp/Pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
12 changes: 12 additions & 0 deletions test/haxe/TestTypes.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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.Function<Int->Int, cpp.abi.Abi>;

public function new() super();

Expand Down Expand Up @@ -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);
}
}