I've started this project to fulfill a need for my new project, gcre8, which aims to be an online game creation engine specifically for the creation of simple games in a similar vein to the old DOS games ZZT and Megazeux. It is not a compiler, but rather, a bytecode interpreter for code compiled with luac. The ultimate purpose is to be used for the client-side game interpreter running on flash 9 or above for running user-created game scripts. Right now the project is in an extreme state of infancy but I'll always appreciate any comments and feedback!
Here's some sample code for Flash to get you going:
import com.gcre8.flua.*;
var p = new Code();
p.addEventListener("ready",ready);
p.parse("http://path/to/your/lua/file.o");
var vm = new Vm(p);
function ready(e) {
vm.run(24);
}
This is the very first baby-steps release, intended mostly to prove that the project isn't complete vaporware. (yet, at least!) Now here's the big disclaimer: If you're looking for clean, happy OO code here, you won't find it. Now, I'd like to think I'm a pretty decent coder, and this actually started out as some really neatly formed and organized object oriented code, but here's the thing... ActionScript is quite slow at this kind of thing. I managed to optimize it to death, and bring it from over 15 seconds (timed out) on the fibonacci sample lua program down to 12 seconds, then further down until I've got to a (fairly remarkable) under one second (~.95 seconds) on my 2.4ghz macbook pro. The damage is that, for optimization's sake, I've had to do away with many of the coding principles I hold dear, such as DRY (Don't Repeat Yourself) and even recursion! (Function calls in the AVM are quite expensive it turns out.) However, if there's any part of the code you'd really like to understand, just toss me an email and I'll be happy to walk you through it, provided I can read it myself! Also, NOT ALL OPCODES ARE IMPLEMENTED OR FULLY TESTED, but most are. That's because this is just a proof-of-concept release that I've only really tested against the fibonacci code. The only builtins right now are tonumber, print, and os.clock. All that being said, this has been fun to work on and I hope to get a mature project going. I'm working at a summer camp as a counselor for two months this summer (mid June-mid August 2008), so coding is going to have to slow down, which is part of the reason I put this one out, since I want to get it started and get some feedback going. And, yes, future release paragraphs should be much, much shorter. :)