My goal, of course, is to never write it again. Let's write JavaScript instead. Thus, zekesonxx/pinecone.
Pinecone is a JS->Lua converter that supports a decent portion of JavaScript. There's still a ton of unsupported things, but it's a start.
Unlike a lot of language converters, this isn't based on regular expressions. Instead, pinecone uses an awesome project called acorn to generate an AST (Abstract Syntax Tree), which is then converted into Lua using a lot of switch statements. This means it's very resilient against lots of weird issues that could arise.
Currently the code is very badly organized and badly commented, however it does work. You need a try.js file in the directory of the code, then to convert the code inside the try.js file, run (with Node.js and deps installed):
$ node convert.js
To then try it in Lua:$ lua try.lua
All outputted code should pass luac, try with:$ luac try.lua
A side-effect of using an AST is that existing formatting and comments get removed. I have a plan on how to get comments back, and smart formatting is done automatically with two spaces (will later be configurable).
The obvious eventual goal is to successfully compile itself and acorn, and then do that with the Lua versions. But, more realistically, the next goals are to reorganize the codebase and start delving into the more complicated conversions (I'm eyeing switches and for loops)
So yeah, feel free to try it out and play with it. It's MIT licensed, enjoy.