Remember how I've been lately pestering about how cool is learning to program in Bash? Well, I'm not retracting, but last couple of days I've been doing the same thing but using
haXe +
Neko +
Xcross. And I like it better.
How is this better than the others?I think it's better than Bash because haXe is an OO language and it's fully crossplatform (no bash in Win unless you use
Cygwin). I also think it's better than
Ant because you get rid of bloody-fatty Java as a dependency.
How is this doneIn a nutshell: you program in haXe, compile to Neko and then pack to a native app using Xcross. Piece of cake!
Let's say you need to read some config file, compile your AS using MTASC and copy the output file to several places. Let's assume a simple config file like this:
[code]tv.zarate.wadus.Main.hx
wadus.swf[/code]
And that we pass it to our tool like this:
[code lang="bash"]tool config.cfg[/code]
Now the pseudo-code:
[code lang="actionscript"]// Get application args, and use the first one
var args : Array<String> = xa.Application.getArgs();
var configPath : String = args[0];
// Read the content of the config file and parse it
var content : String = xa.File.read(configPath);
var lines : Array<String> = content.split("\n");
var class : String = lines[0];
var swf : String = lines[1];
// Call MTASC passing the output swf and the class read from the config file
var args = ["-swf", swf, "-main", class];
var p = new xa.Process(mtascPath, args);
var output = p.getOutput();
var error = p.getError();
var exitCode = p.exitCode();
// Check MTASC exit code, if not 0, something went wrong
if(exitCode != 0)
{
xa.Utils.print(error);
}
else
{
xa.Utils.print(output);
}
[/code]
And now compiling:
[code lang="bash"]haxe -neko wadus.n -main Wadus.hx
haxelib run xcross builder.n[/code]
That should be it; we've read and parsed a config file passed as a parameter and then called MTASC handling the result. Then compiled to native Win, Mac and Linux apps.
As I said, that's pseudo code, on a real life app you would definitely need more error handling or might have a more complex config file (maybe xml, try parsing xml in Bash!), etc., but since haXe is a really similar to Flash or JS, it feels very natural to me. Granted, you can do the same in Bash, but to my eyes is much more complicated.
Some more notes:
- From a Neko app you can call any other tool on your system. That includes SVN, Ant, GIT, grep... Whatever is there, you can call it.
- Apps created with Xcross embed the Neko VM so they have zero dependencies (unless you use any of the tools described above, of course).
We are investigating this route instead of Ant for our build scripts. You might think it's kind of reinventing the Ant wheel, but we have the feeling that this is going to be
much faster and flexible to our needs.
We'll see : )
PS: I've used the xa.* package in the code, that's a little project I'm working on to provide a simpler haXe API for backends. This is a spin-off of HippoHX and it's not ready yet, but if you are interested you can follow the development in
GitHub.