In Haxe, what is the correct way to refer to a define with a dot?
For example, for the library thx.core, how to write conditional compilation against the library name?
#if thx.core
#end
Furthermore, are there general rules for special characters?
The #if flag syntax does not seem to handle dots.
However, Compiler.getDefine() handles most characters, including the dot:
hxml/build command: -D é'"(-è_.çà)=test
#if "é'\"(-è_çà)"
trace('will always be called, even without the -D');
#end
trace(haxe.macro.Compiler.getDefine("é'\"(-è_.çà)")); // test
There is a workaround for dots with initialization macros, even if it is not really pretty:
build.hxml
-x Main.hx
-D abc.def
--macro Macro.parseDefines()
Macro.hx
import haxe.macro.Compiler;
class Macro {
public static macro function parseDefines():Void {
if (Compiler.getDefine("abc.def") != null) {
Compiler.define("abc_def");
}
}
}
Main.hx
class Main {
public static function main() {
#if abc_def
trace("abc.def is defined!");
#end
}
}
Starting with Haxe 4.0.0-rc.2, defines with a dot are permitted in #if as long as they are surrounded by parens:
#if (thx.core)
#end
#if thx.core without parens will likely also work in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With