Passing Custom Class as an Argument back from CPP to Haxe

58 views
Skip to first unread message

Amit Bagga

unread,
Oct 17, 2016, 9:23:50 AM10/17/16
to Haxe

I have a class in c++ which i would like to pass back from C++ to haxe.

i have made an extern for the native class on the haxe side.

how do i pass the value of my object from c++ to haxe on the callback invoke.

i tired inheriting my class from hx::Object but the symbol is missing.

i can convert my object and wrap in as an Abstract Object but i don't want to do that. Please suggest

thank you,
Amit

Hugh

unread,
Oct 18, 2016, 1:41:51 AM10/18/16
to Haxe
I don't think it is going to be possible to extend hx::object in your own code.
So really you must wrap your c++ object in a dynamic to pass to haxe, or use a native function pointer for the callback.
Wrapping is usually done with "alloc_abstract".  It may also be possible to do this with cpp::Struct, but it involves closer mixing of c++ and hxcpp code.
There is nothing really wrong with wrapping as an abstract.  If you are worried about allocation count, you can allocate the abstract once, and recycle it (don't forget AutoGC)  When you receive this in your callback, assign it to a cpp.Pointer<YourType> and you should have direct access to the data.
This is exactly how events are passed in nme in cpp.

Using a native callback would involve making a static function in haxe and using Function.addressOf to pass this to some native code (you would need to resolve the symbol somehow).
Reply all
Reply to author
Forward
0 new messages