Test multiple Haxe target languages with a single script

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 01:12:41

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!