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

MoonScript

Started by toxicwolf, 16 October 2012 - 06:41 PM
toxicwolf #1
Posted 16 October 2012 - 08:41 PM
So I've been playing around with the MoonScript online compiler for a couple of days now, and have really taken a liking to the language.
The best thing obviously is that it compiles into Lua.

As far as I can tell, there needs to be some modifications to CC to allow MoonScript to be added, which I believe are only possible Java-side (such as adding the LPeg module which MoonScript relies on).

It would be nice to have MoonScript in CC alongside Lua, so files with the .moon extension could be run with the moonscript compiler etc.
This could mean that there would be two compiler programs in CraftOS - type 'lua' to access the Lua compiler as normal, and type 'moon' to access the MoonScript compiler.

Overall, I think MoonScript is a nice 'addon' language for Lua as it merges the speed and simplicity of Lua with extra functions such as the ability to do OOP easily via classes, extra keywords/operators (switch statements, with, etc.) and the fact that some keywords like end's and then's can be omitted as the language is more indentation and whitespace aware.
Yes, some of the syntax is different so it may take some getting used to, but I think that it can be picked up by beginners just as quickly as Lua. It is also compatible with existing Lua libraries/functions/APIs etc.

Tell me what you think, because I would really love this to happen :D/>/>
Tiin57 #2
Posted 16 October 2012 - 09:07 PM
I second this. Excellent idea!
toxicwolf #3
Posted 16 October 2012 - 09:58 PM
I second this. Excellent idea!
Thanks :D/>/> Another thing that I like is that programs can often be written better and/or in quite a few less lines than Lua itself, due to both it's syntax omittance and extra features. I suggest having a quick read through the MoonScript reference guide, it highlights some key features that are advantages over Lua.

EDIT: The creator of MoonScript replied to me on Twitter, and it seems that the only major hurdle to implementing MoonScript purely in Lua is the lpeg module. It is probably possible though (albeit by someone more experienced than me) https://twitter.com/moonscript/status/258307515706662913
Edited on 16 October 2012 - 08:15 PM
Cloudy #4
Posted 17 October 2012 - 12:35 AM
Sorry, not gonna happen. We aren't going to implement lpeg into ComputerCraft - would require rewriting it into Java or Lua - neither of which I have any interest in.

I also think it would be confusing having two languages in the mod. If you want to write a Lua version of lpeg though be my guest :D/>/>
toxicwolf #5
Posted 17 October 2012 - 07:30 AM
Sorry, not gonna happen. We aren't going to implement lpeg into ComputerCraft - would require rewriting it into Java or Lua - neither of which I have any interest in.

I also think it would be confusing having two languages in the mod. If you want to write a Lua version of lpeg though be my guest :D/>/>
As much as this saddens me, I completely understand :P/>/> Well now I have the challenge of trying to learn how to write lpeg in Lua.
Tiin57 #6
Posted 17 October 2012 - 12:00 PM
I might make a peripheral using this… Problem is that, while I'm decent with Java, I stink at Forge.
Edit: Cloudy, why don't you have an avatar on the forums? :D/>/>
Cranium #7
Posted 17 October 2012 - 05:33 PM
I might make a peripheral using this… Problem is that, while I'm decent with Java, I stink at Forge.
Edit: Cloudy, why don't you have an avatar on the forums? :D/>/>
He's too cool for avatars.