#if java compiler flag not available in macro?

43 views
Skip to first unread message

Warren Eng

unread,
Apr 17, 2014, 8:52:51 PM4/17/14
to haxe...@googlegroups.com
I've got this macro function that doesn't seem to recognize build target compiler flags:

public static macro function truthy(value:Null<Dynamic>):Expr
{
#if as3
return macro { $value; };
#elseif java
return macro { ($value != null && $value); };
#end
throw "FOOBAR";
return macro {};
}

It always throws "FOOBAR" even though I'm targeting AS3 or Java.

Should this work, or are compiler flags not available at macro time? Thanks!

Cauê Waneck

unread,
Apr 17, 2014, 8:56:35 PM4/17/14
to haxe...@googlegroups.com
Any code that is executed by a macro is executed on a macro context (#if macro), and not by the underlying platform's targets. You'll have to use Context.defined ( http://api.haxe.org/haxe/macro/Context.html#defined ) to check if a flag was defined by the target's context:

if (Context.defined("as3")) { ... }
else if (Context.defined("java")) { ... }


--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/d/optout.

Warren Eng

unread,
Apr 17, 2014, 9:05:28 PM4/17/14
to haxe...@googlegroups.com
Yup, that worked. Thank you very much!
Reply all
Reply to author
Forward
0 new messages