Reputation: 982
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?
Upvotes: 3
Views: 194
Reputation: 34138
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.
Upvotes: 1
Reputation: 1557
In the case of thx.core
, you can use thx_core
(with an underscore):
#if thx_core
#end
As far as I know there is no general support for special characters other than hyphens (those get translated into underscores by the compiler).
The thx.core
library defines -D thx_core
itself, using haxelib's support for extraParams.hxml
.
Upvotes: 0
Reputation: 1847
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
}
}
Upvotes: 2