Passing a string array from Haxe to C++

ah yeah, sorry, I completely skipped over that. Unfortunately hxcpp arrays don’t work with Pointer or RawPointer types so your fromString approach won’t work. What I usually do in situations like this is create an extern around std::vector and use that. For example.

var args = StdVectorString.create();
args.push_back('hello');
args.push_back('world');

myFunction(args.size(), args.data());

Where StdVectorString is the following extern.

@:keep
@:unreflective
@:structAccess
@:include('vector')
@:native('std::vector<const char*>')
extern class StdVectorString
{
    @:native('std::vector<const char*>')
    static function create() : StdVectorString;

    function push_back(_string : ConstCharStar) : Void;

    function data() : RawPointer<ConstCharStar>;

    function size() : Int;
}

By no means the most elegant or convenient solution, but I just put together a small test and it works fine.

1 Like