2017-11-08 8 views
2

Haxeでは、ドットで定義を参照する正しい方法は何ですか?Haxeはドットで定義します

たとえば、ライブラリthx.coreの場合、ライブラリ名に対して条件付きコンパイルを書き込む方法はありますか?

#if thx.core 

#end 

さらに、特殊文字の一般的な規則はありますか?

答えて

1

#if flagシンタックスではドットが処理されないようです。 -D é'"(-è_.çà)=test

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

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

初期化マクロのドットの回避策は、それが本当にきれいでない場合であっても、あります:コマンドを構築/

hxml: しかし、Compiler.getDefine()は、ドットを含むほとんどの文字を扱う

build.hxml

-x Main.hx 
-D abc.def 
--macro Macro.parseDefines() 

Macro.hx

私の知る限りでは

#if thx_core 

#end 

を全く一般的なサポートのためにはありません:

import haxe.macro.Compiler; 

class Macro { 
    public static macro function parseDefines():Void { 
     if (Compiler.getDefine("abc.def") != null) { 
      Compiler.define("abc_def"); 
     } 
    } 
} 

Main.hx thx.coreの場合

class Main { 
    public static function main() { 
     #if abc_def 
     trace("abc.def is defined!"); 
     #end 
    } 
} 
+1

'#if" whatever_string "'は常に真であり、 '-D whatever_string'もありません。 – KevinResoL

+0

正しいですが、私は' #if flag'構文で正しくテストしませんでした。私は回避策で自分の答えを編集しました。 – kLabz

関連する問題