For my roblox-hx project I need to automatically add some extern fields as global variables to be used by any haxe script at any time without having to manually import the module containing these extern fields. The project is for compiling haxe into roblox luau, but luau scripts in roblox have some context information data which auto adds a few global environment variables to the luau vm like the “Script” variable which references the current Script Instance in the engines explorer hierarchy, but i can’t really find a reliable way to bridge the gap for this problem.
What options have you tried so far?
using autoBuild macros which just adds an extern field to the current class but that brings some issues with completion (sometimes the lsp just gives up even if the field exists) and duplicate fields. I saw that the StdTypes.hx file in the haxe std library contains abstracts automatically imported into all scripts, but those are types, not variables/fields…
Just remembered that the trace function is also auto imported from haxe.Log. Does anybody know how that works?
Have you tried making a top-level import.hx file?
I have and that’s the approach that I’m using right now but I’d like to not have an import.hx in every class path on every project made with this lib. Unless there’s some other way to include an import.hx file inside the extraParams.hxml file of my lib which auto adds the given imports to all modules I haven’t discovered.