haxe
haxe copied to clipboard
use namespaced metadata for targets
As briefly discussed in Slack, maybe it makes sense to refactor all the target-specific metadata (@:jsRequire/@:cppInclude/etc.) into namespaced variants (@:js.require, @:cpp.include). If we go with that, we can slowly deprecate the old ones, making them hidden aliases for the new ones and eventually emitting a deprecation warning.
One question here is what to do with target-specific metadata that is shared between a couple different targets, like @:expose for JS and Lua, or @:functionCode for C++, C# and Java.
I think it is a good idea to have it also in the target specific prefix.
Just like js.expose / lua.expose.
If you work in an IDE it can be help for selfdocumented autocomplete.
Just type js. and you see expose in the autocomplete list.
It's probably a good idea to give every platform their own namespaced metadata variant (e.g. @:lua.expose). Otherwise the compiler seems to guarantee that the metadata behavior for the targets will always be the same (I don't believe this is a guarantee we want to make).
It would also be nice to easily combine the namespaced metadata variants back into a single ad-hoc metadata if necessary, at least for projects where any platform differences don't matter. Here's some example code (with syntax I just threw together for illustration):
@:project_require =
#if js
@:js.require
#elseif lua
@:lua.require
#end
Also wanted to reference methods like Compiler.includeFile : https://api.haxe.org/haxe/macro/Compiler.html#includeFile
It's another shared name/behavior between lua and js.