macroshaxe

Haxe: add @:build metadata to all classes in project


Is it possible to apply my type building macro to all classes in a project without modifying their code?

I'm trying to implement a debugger based on Haxe macros: basically I inject calls to my function between every expression in every function of the class. Currently I have an interface IDebuggable and only code in classes that implement that interface can be stopped at breakpoints.


Solution

  • You can use haxe.macro.Compiler.addGlobalMetadata() for this. This can either be done from an initialization macro or on the command line:

    --macro addGlobalMetadata('', '@:build(Build.build())')