This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
zekesonxx's profile picture

I wrote a JavaScript->Lua converter, called Pinecone

Started by zekesonxx, 21 May 2014 - 03:16 AM
zekesonxx #1
Posted 21 May 2014 - 05:16 AM
So, I hate Lua. Like, a lot.
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.
Geforce Fan #2
Posted 30 June 2014 - 07:04 AM
how could you hate lua
begone with you!!!(jk)
sounds cool though.
Edited on 30 June 2014 - 05:04 AM
SquidDev #3
Posted 30 June 2014 - 12:21 PM
I'm impressed. When you can support Prototypes then that would be amazing! Theoretically I could then use CoffeeScript to code on CC. Now that would be awesome!
awsmazinggenius #4
Posted 30 June 2014 - 11:01 PM
If you hate Lua, MoonScript is great too and is intended to be compiled to Lua. Still a neat idea though.
Ampix0 #5
Posted 07 March 2016 - 02:56 AM
Am I to assume this is no longer supported?
masterex1000 #6
Posted 07 March 2016 - 03:31 AM
Finnaly! Something that i can use with ease!!!!!

BTW: javascript is my best known language.
Lupus590 #7
Posted 07 March 2016 - 11:41 AM
Am I to assume this is no longer supported?

try it, if it works then great, if not then try asking someone to port it to the newer CC versions
FUNCTION MAN! #8
Posted 07 March 2016 - 02:38 PM
I'm impressed. When you can support Prototypes then that would be amazing! Theoretically I could then use CoffeeScript to code on CC. Now that would be awesome!

ooh yes that would indeed be divine
zekesonxx #9
Posted 09 July 2016 - 11:38 PM
Heyo. Something possessed me to come look at cc.info, and I totally forgot I had even made a forum post about pinecone.

Pinecone still works, and in fact I recently resumed work on it. At the moment I'm reading the code of other compilers (namely transpilers like CoffeeScript) since pinecone needs some serious restructuring and I'd like to have to restructure it only once.