12.6.8.3 Managed Types

Historically, there has been no correct way to extern a custom hx::Object subclass. While you could use a standard extern class, GC read and write barriers are not generated for them which makes it unsound for various GC features. Managed type externs are finally a way to correctly bring custom hx::Object subclasses into Haxe.

class Foo : public hx::Object {};
@:cpp.ManagedType
extern class Foo {
    function new():Void;
}

function main() {
    final f = new Foo();
}

Managed type externs have very few restrictions and for the most part can be used like and act in the same way as normal Haxe classes.

Flags

StandardNaming

For each Haxe class the compiler generates two C++ types, a hx::ObjectPtr subclass and a hx::Object subclass, with the hx::Object subclass name getting suffixed with _obj.

class Foo {}
class Foo : public hx::ObjectPtr {};

class Foo_obj : public hx::Object {};

If your custom hx::Object subclass follows this naming scheme you can use the StandardNaming flag and the _obj suffix will be added for you.

class Foo_obj : public hx::Object {};
@:cpp.ManagedType({ flags : [ StandardNaming ] })
extern class Foo {}

Details

Inheritance

Standard Haxe classes cannot inherit managed type externs. This is due to a difference in how super calls work in Haxe and C++, this restriction may be modified in the future.