2017-03-22 34 views
0

我也張貼在haxelang這個問題here解析和實例化與非--run進口包和--macro包括

我使用--run命令是,而且一直在努力,包括一些包 運行它的時候,使用--macro包括這樣的:

haxe -lib nape --macro include('nape.geom.Vec2') --run Main 'nape.geom.Vec2' 

然後用Type.resolve這樣我就可以Type.createInstance實例化它們像這樣:

class Main 
{ 
    static function main() 
    { 
    trace("hello", Sys.args()); 
    var c = Type.resolveClass(Sys.args()[0]); 
    trace(c); 
    Type.createInstance(c, []); 
    } 
} 

我也試着用這個命令使用--interp:

haxe -lib nape --macro include('nape.geom.Vec2') -main Main --interp -D nape.geom.Vec2 

他們都跑,跟蹤和接收Sys.args如預期--run(用小代碼更改,以適應「 - D nape.geom.Vec2'for interp),但resolveClass總是返回null,所以我不能將它傳遞給creatInstance而沒有錯誤。

我正在使用haxe 3.4.2穩定

我在做什麼錯?這可能與--run命令或--interp命令?

編號真的很喜歡一些更完整的文檔上的一些功能

回答

1

的「包括」宏包含一個包,而不是一個類。

它適用於:

haxe -lib nape --macro include('nape.geom') --run Main 'nape.geom.Vec2' 

http://api.haxe.org/haxe/macro/Compiler.html#include

+0

運行該命令,它仍然返回null爲類類型。有任何想法嗎? – ediblebird

+0

@ediblebird,[dead code elimination](https://haxe.org/manual/cr-dce.html)或許?也許用'-D dce-debug'編譯產生一些有用的信息。對於單個類,您也可以直接將它們包含在命令行/ build.hxml中:'haxe -lib nape nape.geom.Vec2 --run Main'nape.geom.Vec2'' –