1

I have a class in cpp like:

class Foo{
private:
    int x;
public:
    Foo(){x = 0;}
    int incr();
};

int Foo::incr(){
    x++;
    return x;
}

In any .hx file, I want to use Foo class which is defined in cpp like that:

var number:Int;
// Some codes to create foo_1 object "Foo foo_1;"

// Some codes to call "number = foo_1.incr();"
trace("x is:" + number);
// Some codes to call "number = foo_1.incr();"
trace("x is:" + number);

Expected output is

x is:1
x is:2

As a note, I searched and read some documents about hxcpp and Haxe CFFI but some parts of these documentations are too complicated. I'm beginner in Haxe and I need basic and simple steps to solve this problem. Thanks.

Enes F.
  • 406
  • 6
  • 17

1 Answers1

0

I tried getting this to work once for a research project and it was far from simple. The documentation is pretty scarce and short of reverse engineering hxcpp, there's little else to go on.

That said, as far as I know, extern classes are the only way to access C++ objects from Haxe directly. Not without some scaffolding though.

You can read about one guy's experience here.

Zoli
  • 1,137
  • 7
  • 12