I'd like to dynamically add some new Types to a given Module based on some files found in a directory.
I'm essentially trying to populate a bunch of @:file(...)
embed classes at the bottom of a Module.
//This is the module I'm targeting to append embedded ByteArray subtypes (see below)
@:build(macros.AutoEmbed.build("some/folder/"))
class Embeds {
//Empty on purpose, just let the Macro do its thing!
}
// At "macro-time", it should generate these:
@:file("some/folder/ui_main.xml")
class UI_MAIN_XML extends flash.utils.ByteArray { }
@:file("some/folder/config.template.json")
class CONFIG_TEMPLATE_JSON extends flash.utils.ByteArray { }
What I've been able to find so far is that I might have to alter the Embeds.hx
module. So I looked into Context.getModule( Context.getLocalModule() )
. I've also looked into TypeDefinition
since it seems like the only way to define a new type from scratch.
The problem with Context.getModule(...)
though is that it returns an array Array<Type>
, not Array<TypeDefinition>
, so I can't append new TypeDefinition
to it (plus I have to figure out how to write those, ughh). That's probably a bad assumption on my part, but I thought by simply appending more TypeDefinition
to it I could dynamically provide more types in the module.
I'm still very new to Macros as you can tell!
EDIT
It's true that I could just dynamically write/overwrite a new Embeds.hx
file at compile-time with a FileSystem / File write solution, but that implies needing to compile at least once before your IDE's auto-completion can pickup the generated Embeds.*
classes (FlashDevelop in my case). Plus anytime new files are dropped in the defined folder, same problem: you need to compile first before the IDE detects it. Yes, I really like auto-completion :)
Tmp
come from in themacro class Tmp extends haxe.io.BytesData
part? And can I still extend flash.utils.ByteArray instead of haxe's version (not sure about the difference between the two to be honest...)? – Drive