💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
Haxe允许通过使用 #if 、#elseif 和 #else 进行条件编译,并检查编译器标记。 > Haxe allows conditional compilation by using #if, #elseif and #else and checking for compiler flags. >[warning] 定义:编译器标记 一个编译器标记是一个配置值,可以改变编译过程。可以调用命令行使用 -D key=value 或者 只有 -D key的形式对标记进行设置,只有key的时候值默认为 1 。编译器也设置了一些内部标记在不同的编译步骤之间传递信息。 >[warning] **Definition**: Compiler Flag > A compiler flag is a configurable value which may influence the compilation process. Such a flag can be set by invoking the command line with -D key=value or just -D key, in which case the value defaults to "1". The compiler also sets several flags internally to pass information between different compilation steps. 这个例子展示了条件编译的用法: > This example demonstrates usage of conditional compilation: ~~~ class Main { public static function main(){ #if !debug trace("ok"); #elseif (debug_level > 3) trace(3); #else trace("debug level too low"); #end } } ~~~ 不使用任何标记编译只保留 trace("ok"); 这行。另一个分支在解析文件时被丢弃。这些其他的分支必须包含有效的Haxe语法,但是代码不会执行类型检查。 > Compiling this without any flags will leave only the trace("ok"); line in the body of the main method. The other branches are discarded while parsing the file. These other branches must still contain valid Haxe syntax, but the code is not type-checked. \#if 之后的条件和 \#elseif之后的条件允许如下的表达式: > The conditions after #if and #elseif allow the following expressions: * 任何标识符被编译器标记替换为同名的。注意 -D -some-flag 指示标记 some-flag,somin_flag被定义。 * String,Int和Float常量值被直接使用。 * 布尔操作符 &&, || ,和 ! 如同预期那样工作,然而整个表达式必须被完全放在括号中。 * 操作符 ==,!=,>, >=,<,<=可以用来对比值。 * 括号可以用来像往常一样组织表达式。 > * Any identifier is replaced by the value of the compiler flag by the same name. Note that -D some-flag from command line leads to the flags some-flag and some_flag to be defined. > * The values of String, Int and Float constants are used directly. > * The boolean operators && (and), || (or) and ! (not) work as expected, however the full expression must be completely contained by parentheses. > * The operators ==, !=, >, >=, <, <= can be used to compare values. > * Parentheses () can be used to group expressions as usual. Haxe解析器不解析 some-flag为一个字符串令牌,而是将她读为一个减法二院操作符 some - flag 。这种情况,下划线的版本 some_flag 就有使用的必要了。 > The Haxe parser does not parse some-flag as a single token and instead reads it as a subtraction binary operator some - flag. In cases like this the underscore version some_flag has to be used. **内建编译器标记** 一个所有内部定义的详尽列表可以通过在Haxe编译器 调用 --help-defines 参数来获得。Haxe编译器在每次编译允许多个 -D 标记。 > **Built-in Compiler Flags** An exhaustive list of all built-in defines can be obtained by invoking the Haxe Compiler with the --help-defines argument. The Haxe Compiler allows multiple -D flags per compilation. 也可以查看编译器标记列表(第7.1节)。 > See also the Compiler Flags list (7.1).