2017-11-08 2 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"'은 항상 true이고, 심지어'-D whatever_string'도 없다. – KevinResoL

+0

네 말이 맞아, 나는'#if flag '구문으로 올바르게 테스트하지 않았다. 해결 방법으로 내 대답을 편집했습니다. – kLabz