I read in the Haxe API reference that ArrayAccess interface is used to indicate that an extern class supports array access. But it won’t work for me.
Sample code
import cpp.*;
@:unreflective
@:structAccess
@:include("array")
@:native("std::array<int, 10>")
extern class NativeIntArray implements ArrayAccess<Int> {
public function size():SizeT;
public function at(index:Int):Int;
public function data():RawPointer<Int>;
public static inline function create():NativeIntArray {
return untyped __cpp__("{}");
}
}
class Main {
static function main() {
var myArray = NativeIntArray.create();
myArray[0] = 555;
trace('The value at index 0 is ${myArray[0]}');
}
}
The generated code for this is
void Main_obj::main(){
std::array<int, 10> myArray = {};
( ( ::Dynamic)(( (cpp::Struct< std::array<int, 10> >)(myArray) )) )->__SetItem(0,555);
::haxe::Log_obj::trace((HX_("The value at index 0 is ",c9,66,be,b9) + ( ( ::Dynamic)(( (cpp::Struct< std::array<int, 10> >)(myArray) )) )->__GetItem(0)),hx::SourceInfo(HX_("src/Main.hx",9a,7a,30,a1),21,HX_("Main",59,64,2f,33),HX_("main",39,38,56,48)));
}
I would have expected myArray[0] = 555
. However it is creating a cpp::Struct instance, casting it to Dynamic and calling __SetItem on it instead. It doesn’t work either.
Is this a bug or am I doing something wrong?