creating typedefs with macros

254 views
Skip to first unread message

Michael Baczynski

unread,
Mar 3, 2013, 11:38:08 AM3/3/13
to haxe...@googlegroups.com
Hi,

I want to generate a hierarchical structure of typedefs by feeding an xml file to a macro. The result should look like this:

typedef Base = { var val:String; }
typedef A = { > Base, var b:B; }
typedef B = { > Base, var c:C; }
typeDef C = { > Base; }
...

I know there is haxe.macro.MacroType<[MyMacro.eval()]> for this, but I don't have a clue how to write eval().
Anyone can point me in the right direction?

best,
Michael

Juraj Kirchheim

unread,
Mar 3, 2013, 11:42:49 AM3/3/13
to haxe...@googlegroups.com
In essence the macro that is a parameter to MacroType must return a
haxe.macro.Type.

But from the looks of it, what you are trying to accomplish is best
achieved through Context.defineType. Did you try that?

Regards,
Juraj

Michael Baczynski

unread,
Mar 3, 2013, 3:33:38 PM3/3/13
to haxe...@googlegroups.com
Hi,

thanks. The problem is I can't figure out how to define a TypeDef, e.g. Context.defineType({ magic expression })

Juraj Kirchheim

unread,
Mar 3, 2013, 4:45:36 PM3/3/13
to haxe...@googlegroups.com
Uhm, ok, well hard to say without knowing where exactly you are stuck ;)

Here's a minimal working example to declare the exact types you want
to declare: https://gist.github.com/back2dos/5078439
When you call Build.types() from some macro, these types will be defined.

Hope that clarifies things. If not, just ask ;)

Regards,
Juraj

Michael Baczynski

unread,
Mar 13, 2013, 4:23:16 PM3/13/13
to haxe...@googlegroups.com
sorry for late response - I suffered a really bad cold the past days.
your code example is exaclty what I needed, nice and clean :)
thanks!
Reply all
Reply to author
Forward
0 new messages