Skip to content

[PROPOSAL] Operator overload for function calls #103

@EliteMasterEric

Description

@EliteMasterEric

Haxe currently allows for abstracts to redefine unary operators such as a++, as well as binary operators, such as a + b, and even other operators such as ternary, range, or array access. However, based on the documentation I have read, it does not currently allow overriding the function call operation.

I would imagine this would look something like so:

abstract CallableThing(CallableThingBase) {
  @:op(Int, Bool)
  public function call(arg1:Int, arg2:Bool):Void {
    trace('Arg 1: $arg1');
    trace('Arg 2: $arg2');
  }
}

...

var c:CallableThing = new CallableThing();
// You can now make calls to C as though it were an Int->Bool->Void function.
c(1, true);

At compilation time, c(1, true) would be replaced with CallableThing_Impl_.call(c, 1, true).

The main sticking points here is the actual syntax; @:op(Int, Bool) is redundant since we already have the function signature, @:op(()) can't necessarily be interpreted by the compiler I don't think, and the @:callable metadata is already in use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions