Jump to content




I wrote a JavaScript->Lua converter, called Pinecone

lua api computer

  • You cannot reply to this topic
8 replies to this topic

#1 zekesonxx

  • Signature Abuser
  • 263 posts
  • LocationWhere you aren't

Posted 21 May 2014 - 04: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.

#2 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 30 June 2014 - 06:04 AM

how could you hate lua
begone with you!!!(jk)
sounds cool though.

Edited by Geforce Fan, 30 June 2014 - 06:04 AM.


#3 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 30 June 2014 - 11:21 AM

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!

#4 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 30 June 2014 - 10:01 PM

If you hate Lua, MoonScript is great too and is intended to be compiled to Lua. Still a neat idea though.

#5 Ampix0

  • Members
  • 21 posts

Posted 07 March 2016 - 02:56 AM

Am I to assume this is no longer supported?

#6 masterex1000

  • Members
  • 10 posts

Posted 07 March 2016 - 03:31 AM

Finnaly! Something that i can use with ease!!!!!

BTW: javascript is my best known language.

#7 Lupus590

  • Members
  • 2,028 posts
  • LocationUK

Posted 07 March 2016 - 11:41 AM

View PostAmpix0, on 07 March 2016 - 02:56 AM, said:

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

#8 FUNCTION MAN!

  • Members
  • 292 posts

Posted 07 March 2016 - 02:38 PM

View PostSquidDev, on 30 June 2014 - 11:21 AM, said:

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

#9 zekesonxx

  • Signature Abuser
  • 263 posts
  • LocationWhere you aren't

Posted 09 July 2016 - 10: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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users