Add code to constructor via build macro

48 views
Skip to first unread message

Adrian

unread,
Dec 8, 2014, 9:56:11 AM12/8/14
to haxe...@googlegroups.com
Hi all,

I want to add a few lines of code to a constructor via build macro.
Now I know how to create entire fields but not how to add code to a existing function.
This is normally the approach I use to implement a build  macro: https://gist.github.com/adrianmm44/71562a14f512503447d3

In this case I would want to add foo = new Array(); to an already existing constructor.
Could someone enlighten me how to achieve this?

Best, Adrian

Juraj Kirchheim

unread,
Dec 8, 2014, 10:15:43 AM12/8/14
to haxe...@googlegroups.com
It should look something like this:

  var fields = Context.getBuildFields();

  for (f in fields)
    switch f {
      case { name: 'new', kind: FFun(f) }:
        f.expr = macro { ${f.expr}; foo = new Array() };
      default:
    }

Best,
Juraj

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Adrian

unread,
Dec 8, 2014, 2:03:23 PM12/8/14
to haxe...@googlegroups.com
Just what I needed! :)

Thanx a lot Juraj

Op maandag 8 december 2014 16:15:43 UTC+1 schreef back2dos:
Reply all
Reply to author
Forward
0 new messages