问题
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) Compile Haxe source code to JavaScript, C++, PHP, and Java.
2) Display the output of the Haxe program in each target language.
回答1:
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.
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.
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"
来源:https://stackoverflow.com/questions/13506879/test-multiple-haxe-target-languages-with-a-single-script