Main.hx 480 B

12345678910111213141516171819202122232425
  1. import haxe.macro.Context;
  2. import haxe.macro.Expr;
  3. using haxe.macro.Tools;
  4. abstract Foo(Dynamic) from Dynamic to Dynamic {
  5. @:op(A.B) function get(prop:String) {
  6. return Reflect.field(this, prop);
  7. }
  8. @:op(A.B) macro function set(obj:Expr, prop:Expr, val:Expr) {
  9. var s = Context.getTypedExpr(Context.typeExpr(obj)).toString();
  10. Sys.stderr().writeString(s);
  11. return macro $val;
  12. }
  13. }
  14. class Main {
  15. static function main() {
  16. var foo:Foo = {
  17. n: 5
  18. };
  19. foo.n += 4;
  20. }
  21. }