Skip to content

Instantly share code, notes, and snippets.

@jcward
Last active October 20, 2017 17:19
Show Gist options
  • Save jcward/fd94f5752c2855e0af9f to your computer and use it in GitHub Desktop.
Save jcward/fd94f5752c2855e0af9f to your computer and use it in GitHub Desktop.
Print compiler defines from a macro in Haxe
// Note: Context.getDefines() requires Haxe 3.2 or later
class Main { // example main class
// - - - - - - - - - - - - - - - - - - - - - - - - - -
// Just paste this code into one of your classes:
// - - - - - - - - - - - - - - - - - - - - - - - - - -
macro public static function get_defines():haxe.macro.Expr {
var rtn = "Defines ("+
(haxe.macro.Context.defined("macro")?"macro":"standard")+" pass):\n";
var defines:Map<String,String> = haxe.macro.Context.getDefines();
for (key in defines.keys()) {
rtn += "-D "+key+"="+defines.get(key)+"\n";
}
trace(rtn); // compile-time trace
return {expr: EConst(CString(rtn)) , pos : haxe.macro.Context.currentPos()};
};
private static var __invoke_defines = get_defines();
// - - - - - - - - - - - - - - - - - - - - - - - - - -
static function main() {
}
}
>haxe Main.hx -main Main -D foo=3
Main.hx:15: Defines (macro pass):
-D haxe_ver=3.2
-D macro=1
-D sys=1
-D foo=3
-D dce=std
-D hxcpp_api_level=321
-D true=1
-D cross=1
-D neko=1
-D haxe3=1
Main.hx:15: Defines (standard pass):
-D haxe_ver=3.2
-D sys=1
-D foo=3
-D dce=std
-D hxcpp_api_level=321
-D true=1
-D cross=1
-D haxe3=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment