Hxcpp Array of native extern

173 views
Skip to first unread message

Pablo Martin

unread,
Jan 12, 2016, 7:40:35 PM1/12/16
to Haxe
Hi everyone.

I have some problems when i try to work with Array and a native extern. Here an example:

@:include("cc_orientation.h")
@:native("cc::Orientation")
extern class Orientation
{
    @:native("cc::Orientation")
    static function create():Orientation;
}

class Main {
static function main() {
var array = new Array<Orientation>();
array.push(Orientation.create());
}
}


It gives me the next error:

./src/Test2.cpp(50): error C2664: 'int Array_obj<ELEM_>::push(ELEM_)': cannot convert argument 1 from 'cc::Orientation' to 'Dynamic'
        with
        [
            ELEM_=Dynamic
        ]
./src/Test2.cpp(50): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Any help?

Thanks in advance.

Hugh

unread,
Jan 12, 2016, 11:46:31 PM1/12/16
to Haxe
This is currently not going to work with hxcpp without some compiler fixes.
You can do an array of cpp::References to your structure, but you would need to delete the elements at some stage.
You could also make an "extern OrientationArray" class (implemented, say, with a pointer to a  std::vector) and access it that way.

Hugh

Hugh

unread,
Jan 12, 2016, 11:48:02 PM1/12/16
to Haxe
I think you could also make a byte-array of appropriate size, and cast a cpp.Pointer to its base, giving you array-like access to byte data.
But I have not looked too closely at this.

Hugh

Pablo Martin

unread,
Jan 13, 2016, 9:51:54 AM1/13/16
to Haxe
Thanks! The OrientationArray solution could work for now (i need to convert it with my external library in a std::vector anyway). Is it planned to work with Array in the future?

A question: is it possible to get a generic StdVector class? Something like that:

@:include("vector")
@:native("std::vector")
extern class StdVector<T> { }

The problem is that it requires the template argument list in the @:native sentence, and i don't know how i could insert it.

Thanks again.

Hugh

unread,
Jan 13, 2016, 11:33:01 PM1/13/16
to Haxe
You can't really get the haxe "<T>" in there, but you might be able to do something like:

@:include("vector")
extern class StdVector<T> {
   
// haxe defs go here, with <T>
}


@:native("std::vector<MyClass>")
 
extern class MyClassVector extends StdVector<MyClass> { /* Defs are common - maybe a specific create call */ }

So almost all the haxe code is common, but you have a couple of lines per class.
A word of warning about std::vector - the constructors/destructors will not be called if you store them in member variables, so you will need to add some funky destroy() commands.  If you store pointers, you will need to delete them.

Hugh

Pablo Martin

unread,
Jan 14, 2016, 2:58:24 AM1/14/16
to Haxe
Thanks again! I am very grateful ;)
Reply all
Reply to author
Forward
0 new messages