I’m hoping to use Haxe to output relatively idiomatic APIs in a bunch of target languages, so that I can call my routines from Java and JS projects and my friend can call routines from C++ projects. If I have class Unit the output C++ is class HXCPP_CLASS_ATTRIBUTES Unit_obj…how can I turn off the _obj suffix? Haxe doesn’t do anything like this for Java output.
I guess if nothing else I can do a find and replace…
The hxcpp output isn’t very idiomatic, because c++ and haxe don’t have the same semantics on many things.
It isn’t just about the _obj suffix, if also doesn’t use new since you need a GC allocation, and in haxe you don’t have to call the super constructor as the first instruction in a constructor, but c++ does.
Arrays are pretty special and need casting and possibly boxing for the elements.
The GC needs to be init and called.
I wouldn’t recommend using hxcpp to create a c++ library.
Huh, that makes sense, though looking more at the C++ output (esp how arrays need casting), I think I’m probably not going to be able use Haxe for creating cross-language libraries.
Try to look at @:nativeGen. It should generate clean interface which helps to interact with Haxe classes.
You can find a small example of how to implement API with @:nativeGen here:
And here is an example of how to use generated classes in cpp:
Some platforms are more suitable for making libraries for using from the target language than others. Js has a lot of options, see GitHub - kevinresol/hxgenjs: Extensible JS generator for Haxe. Python, on the other hand, is troublesome because it lumps everything into one file, meaning the class names are all mangled (and I’ve been meaning to learn some ocaml so I could try fixing that).