Get type of an object in a Haxe macro

Viewed 502

I would like to get the class of an object in a macro so that I can access its static variables:

// autoBuild macro adds static field "id_ : Int" to all subclasses
class Base {

}

class Child1 extends Base {
  public function new() {}
}

class Child2 extends Base {
  public function new() {}
}

class Container {
  public function addChild(index: Int, object: Base) {}

  macro function add(object: ???) {
    // find out class of on object
    // ???
    // var id = class.id_;
    this.addChild(id, object);
  }
}

Desired usage:

var c = new Container();
c.add(new Child1());
c.add(new Child2());
1 Answers
Related