Skip to content

Instantly share code, notes, and snippets.

@jasononeil
Created March 25, 2013 02:25
Show Gist options
  • Save jasononeil/5234547 to your computer and use it in GitHub Desktop.
Save jasononeil/5234547 to your computer and use it in GitHub Desktop.
haxe.macro.Compiler.define() example
/**
* Macro Compiler Define example
*
* Shows how to use a compiler configuration macro to set up more "defines" based
* on an existing define.
*
* Jason O'Neil 2013. Use as you please.
*
* haxe -D mydebug --macro "MacroDefine.setDefines()" -x MacroDefine.hx
* -- traces "A" and "B"
* haxe -D myrelease --macro "MacroDefine.setDefines()" -x MacroDefine.hx
* -- traces "B" and "C"
* haxe -x MacroDefine.hx
* -- doesn't trace anything
*/
#if macro
import haxe.macro.Context;
#end
class MacroDefine
{
public static function setDefines()
{
#if mydebug
haxe.macro.Compiler.define("A");
haxe.macro.Compiler.define("B");
#elseif myrelease
haxe.macro.Compiler.define("B");
haxe.macro.Compiler.define("C");
#end
}
static function main()
{
trace ("Here are the defines: ");
#if A
trace ("A");
#end
#if B
trace ("B");
#end
#if C
trace ("C");
#end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment