Haxe: add @:build metadata to all classes in project
Asked Answered
K

1

3

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.

Kaenel answered 28/6, 2016 at 11:39 Comment(0)
F
7

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())')
Farly answered 28/6, 2016 at 11:51 Comment(3)
Is it possible to distinguish between standart or library classes and project classes? Currently I've added this code, but this is ugly: var module = Context.getLocalModule(); if (module == 'DebugRuntime' || module.indexOf('haxe') == 0 || module.indexOf('flash') == 0) return null;Kaenel
You can make use of the pathFilter argument.Farly
Do not see how can I use it. It allows to filter only one prefix. But most projects have a lot of different packages. I think it is possible to filter based on file path and get file path from Context.CurrentPos, but for this I need project source paths.Kaenel

© 2022 - 2024 — McMap. All rights reserved.