[英]Haxe: Import from neko, cpp and java sys trees
I want to use Haxe to write a library that can be used by other projects in various different languages. 我想使用Haxe编写一个库,该库可以供其他项目以各种不同的语言使用。
Currently I have at the top of my library: 目前,我在图书馆的顶部:
import neko.io.File;
import neko.io.FileInput;
import neko.io.FileOutput;
import neko.FileSystem;
import neko.io.Process;
So my library compiles to neko just fine, using the -neko
flag. 因此,我的库可以使用
-neko
标志编译为neko。 However if I try to use the -cpp
flag, the packages cannot be found: 但是,如果尝试使用
-cpp
标志,则找不到软件包:
$ haxe -cp src -main sws/Root.hx -cpp build/sws.CXX
src/sws/Root.hx:3: characters 0-20 : You can't access the neko package with current compilation flags (for neko.io.File)
I thought the solution would be to instead do the imports like this: 我认为解决方案将改为执行以下导入:
import sys.io.File;
import sys.io.FileInput;
import sys.io.FileOutput;
import sys.FileSystem;
import sys.io.Process;
and let Haxe change sys
into neko
or cpp
depending on the compile flag I use. 然后根据我使用的编译标志,让Haxe将
sys
更改为neko
或cpp
。 (Assuming all the modules are available in all the target languages.) But that doesn't work either. (假定所有模块都支持所有目标语言。)但这也不起作用。
$ haxe -cp src -main sws/Root.hx -neko build/sws.n
src/sws/Root.hx:3: characters 0-19 : Class not found : sys.io.File
$ haxe -cp src -main sws/Root.hx -cpp build/sws.CXX
src/sws/Root.hx:3: characters 0-19 : Class not found : sys.io.File
How should I be doing it? 我应该怎么做?
If import neko.io.File;
如果
import neko.io.File;
works, you're probably using Haxe 2.x, not Haxe 3. (Unless I'm missing something?) 起作用,您可能正在使用Haxe 2.x,而不是Haxe3。(除非我缺少某些内容?)
In Haxe 3, you would use import sys.io.File
etc. Migration notes for Haxe 3 can be found at: http://haxe.org/manual/haxe3/migration 在Haxe 3中,可以使用
import sys.io.File
等import sys.io.File
3的迁移说明可以在以下位置找到: http : import sys.io.File
In Haxe 2, you had to do it per target. 在Haxe 2中,您必须针对每个目标执行此操作。 I would do things like:
我会做类似的事情:
#if neko
import neko.io.File;
import neko.io.FileInput;
import neko.io.FileOutput;
import neko.FileSystem;
import neko.io.Process;
#elseif cpp
import cpp.io.File;
import cpp.io.FileInput;
import cpp.io.FileOutput;
import cpp.FileSystem;
import cpp.io.Process;
#end
Assuming of course all those classes existed in the CPP target on your Haxe release. 当然,假设所有这些类都存在于Haxe版本的CPP目标中。
If not, maybe look at upgrading to Haxe 3 :) 如果没有,也许看看升级到Haxe 3 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.