Typdef compilation to C#


Regarding to THIS

I have a question. I have

typedef Point = Array<Float>;

which is implemented in GitHub - pboyer/verb: Open-source, cross-platform NURBS

And I try to compile to c#, but all Points are changed to object .
How can i fix it?

I can change it to for example.:

class Point extends SerializableBase {

   public var x: float;
   public var y: float;

   public function new(x, y){
        this.x= x;
        this.y= y;

But then all places where simple array of floats is used (almost 800 places in whole lib) will be incompatible.

Any help?

Haxe Array is not the best structure for exposure in a cross-target library.
Because of its semantics it’s usually not mapped to native array on a target platform.
An since point is a fixed structure of two values your best bet is changing it into a class Point.
Another option is to declare Point as an abstract on top of native arrays:

private typedef Native = 
  #if cs cs.NativeArray<Float> 
  #elseif java java.NativeArray<Float>

abstract Point(Native) {
  public var x(get,set):Float;
  inline function get_x() return this[0];
  inline function set_x(v:Float) return this[0] = v;

  public var y(get,set):Float;
  inline function get_y() return this[1];
  inline function set_y(v:Float) return this[1] = v;


That abstract could also be iterable and offer array access instead of .x and .y to mimic Array<Float> API. That would allow to reduce required effort for adapting existing code to a new type.

Thank you for fast reply!!!
I’m totally new to Haxe, and I just wanted to use ready-made lib in c# but it seams problematic.

After application of your suggestion I have we:

src/verb/eval/Intersect.hx:67: characters 46-83 : error: verb.core.Point should be Array<Float>
src/verb/eval/Intersect.hx:67: characters 46-83 :  have: Array<verb.core.Point>
src/verb/eval/Intersect.hx:67: characters 46-83 :  want: Array<Array<...>>
src/verb/eval/Intersect.hx:67: characters 46-83 : For function argument 'points'

Applying Iterator maybe help me with that.
I should just follow this: Iterators - Haxe - The Cross-platform Toolkit


I’ve try somethink like this:

abstract Point(Array<Float>){
    inline public function new(i:Array<Float>) {
        this = i;
    public inline function get(k:Int) {
      return this.get(k);
    public inline function set(k:Int, v:Float) {
        this.set(k, v);

But still same error…

If you just want to use an existing library from C# and you’re new to Haxe, then it’s probably easier for you to create a test project using that lib from Haxe, build that project to Haxe/C# target and look into generated C# to get an idea how to use the library from C# without changing it.