Operator overloading in C# output library


(Bary Levi) #1

I am writing a library to be used from C#, and I want to provide its users with C# operator overloading. It seems @:op is only for Haxe abstracts, and the following doesn’t compile

public static function operator+(Vector2D a, Vector2D b): Vector2D {
    return new Vector2D(a.x + b.x, a.y + b.y);

as operator+ is not a valid Haxe identifier.

I tried to give the function a different name and use @:native("operator+") but that didn’t work either.

Is there a way to do this? I didn’t manage to find any way.