import sys.io.File;
import haxe.macro.Context;
import haxe.macro.Expr;
class Macro {
macro static public function build(): Array<Field> {
final fields = Context.getBuildFields();
if (fields.length > 0) return fields;
trace("invalidate", fields.map(struct -> struct.name));
final resPath = "./files.txt";
final content = File.getContent(resPath);
final lines = content.split("\n");
Context.registerModuleDependency(Context.getLocalModule(), resPath);
for (name in lines) {
if (name.length == 0) continue;
fields.push({
name: name,
access: [APublic, AStatic],
kind: FVar(macro :Int),
pos: Context.currentPos()
});
}
return fields;
}
}
In vscode, after i change files.txt on latest stable release, invalidate triggers once after i focus on Main file where i use generated Module with this build macro.
On development, invalidate triggers on every Main save/focus now, because getBuildFields stops returning already builded fields after prev build.
Project: regdep.zip
And let me know if my macro is bad and i should use @:persistent there for simple file cache or something else.
In vscode, after i change
files.txton latest stable release,invalidatetriggers once after i focus onMainfile where i use generated Module with this build macro.On development,
invalidatetriggers on everyMainsave/focus now, becausegetBuildFieldsstops returning already builded fields after prev build.Project: regdep.zip
And let me know if my macro is bad and i should use
@:persistentthere for simple file cache or something else.