问题描述
在Haxe中,是否有任何脚本或命令可以自动以多种目标语言运行Haxe程序?我想编写一个执行以下操作的脚本:
In Haxe, is there any script or command that can automatically run a Haxe program in multiple target languages? I'd like to write a script that does the following:
1)将Haxe源代码编译为JavaScript,C ++,PHP和Java.
1) Compile Haxe source code to JavaScript, C++, PHP, and Java.
2)用每种目标语言显示Haxe程序的输出.
2) Display the output of the Haxe program in each target language.
推荐答案
您可以使用普通的hxml和一个特殊的js运行时来执行此操作,该运行时可将其输出到终端.我正在使用 phantomjs ,但其他环境(例如node.js)也是可能的.
You can do this with normal hxml, and a special js runtime that lets you output to the terminal. I'm using phantomjs, but other environments like node.js are possible.
请注意,我需要添加附加特定的退出命令,以使phantomjs正确退出.有关更多详细信息,请参见phantomjs文档.您还需要从haxelib安装hxjava和hxcpp.
Note that I need to add append a specific exit command in order for phantomjs to exit properly. See the phantomjs docs for more details. You'll also need to install hxjava and hxcpp from haxelib.
我在这里使用--next
一次完成多个编译.您可以轻松地将其分解为多个hxml文件,并通过makefile等对其进行管理.
I'm using --next
here to do multiple compilations in one pass. You can easily break this up into multiple hxml files, and manage it via a makefile, etc.
-main Main
-php php
-cmd echo "PHP:"
-cmd php php/index.php
-cmd echo "\n"
--next
-main Main
-js bin/Main.js
-cmd echo "phantom.exit();" >> bin/Main.js
-cmd echo "JS:"
-cmd phantomjs bin/Main.js
-cmd echo "\n"
--next
-main Main
-cpp cpp
-cmd echo "CPP:"
-cmd ./cpp/Main
-cmd echo "\n"
--next
-main Main
-java java
-cmd echo "JAVA:"
-cmd java -jar java/java.jar
-cmd echo "\n"
这篇关于使用单个脚本测试多种Haxe目标语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!