Haxe用dot定义

问题描述 投票:3回答:3

在Haxe中,使用点引用定义的正确方法是什么?

例如,对于库thx.core,如何针对库名写入条件编译?

#if thx.core

#end

此外,是否有特殊字符的一般规则?

haxe conditional-compilation
3个回答
2
投票

#if flag语法似乎不处理点。但是,Compiler.getDefine()处理大多数字符,包括点:

hxml / build命令:-D é'"(-è_.çà)=test

#if "é'\"(-è_çà)"
trace('will always be called, even without the -D');
#end

trace(haxe.macro.Compiler.getDefine("é'\"(-è_.çà)")); // test

有一个带有初始化宏的点的解决方法,即使它不是很漂亮:

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
    }
}

1
投票

Starting with Haxe 4.0.0-rc.2,在#if中允许使用点定义,只要它们被parens包围:

#if (thx.core)

#end

#if thx.core无父will likely also work in the future


0
投票

thx.core的情况下,您可以使用thx_core(带下划线):

#if thx_core

#end

据我所知,对连字符以外的特殊字符(those get translated into underscores by the compiler)没有普遍的支持。

thx.coredefines -D thx_core本身,使用haxelib的support for extraParams.hxml

© www.soinside.com 2019 - 2024. All rights reserved.