Jump to content




Moonscript - An alternative way to writing in lua.


12 replies to this topic

#1 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 11 October 2012 - 10:10 PM

A long time ago, I found this neat little thing called moonscript. It's another language, described as programmer-friendly, that compiles into Lua.

I'm obviously not going to list all of the features here, since it adds and changes a lot, but I'll name some notable ones that I've enjoyed using.

Assignment operators:
foo = 5
foo += 3
foo -= 4
foo /= 2
foo *= 3
foo ..= 'bar'

No need for ends, thens or dos (with some exceptions):
if Moonscript
  print 'Awesome!'

No need for parentheses (with some exceptions):
term.setCursorPos 1,1

Switch statement:
switch 'toast'
  when 'bagel'
	print "That's cool."
  when 'eggs'
	print "Meh."
  when 'butter'
	print "wtf is your problem"
  else
	print "...What are you even eating?"

Alternate function calling (without arguments):
afunction!

Alternate function declaration (without arguments):
afunction = ->
  somecode!

Automatic localization ("export" is used to make global):
declare_var = ->
  x = 5

declare_var!

if x
  print "x is global!"
else
  print "I can't find x!" --should print this

There's a lot more to know about moonscript than what I've shown here, if you're interested. There's some helpful documentation on the moonscript website. I've written some things in CC using moonscript, and once you understand what it actually is, it becomes really easy to understand.

http://moonscript.org/

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 11 October 2012 - 10:23 PM

Looks as though it was inspired by a lot of other languages.

For me, python comes to mind.

#3 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 11 October 2012 - 11:13 PM

Really cool! How many lines of code is it? :P/>

#4 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 12 October 2012 - 12:09 AM

View Postjag_e_nummer_ett, on 11 October 2012 - 11:13 PM, said:

Really cool! How many lines of code is it? :P/>
Looking through the source...

a lot.

#5 toxicwolf

  • Members
  • 201 posts
  • LocationUnited Kingdom

Posted 12 October 2012 - 01:55 PM

This is really interesting! Could you tell me how you'd go about installing Moonscript for CC?

#6 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 12 October 2012 - 07:20 PM

View Posttoxicwolf, on 12 October 2012 - 01:55 PM, said:

This is really interesting! Could you tell me how you'd go about installing Moonscript for CC?
You don't need to do anything specifically for CC. Because of how moonscript complies to lua, you can just use CC APIs in it.

Simple password program in moonscript:
pass = "a password"

while true
  term.clear!
  term.setCursorPos 1,1
  print "Please enter the password."
  input = read!
  if input == pass
	print "Access granted."
	rs.setOutput 'right', true
	sleep 3
	rs.setOutput 'right', false
  else
	print "Access denied."
	sleep 2
No doubt I made a mistake somewhere in there though, haha.

#7 GopherAtl

  • Members
  • 888 posts

Posted 12 October 2012 - 07:30 PM

until/unless someone ports it, you can't use it in cc. You can only use it outside cc to compile moonscript programs into lua programs for use in CC.

:edit: or, it might be possible to use this web demo with the http api http://moonscript.org/compiler/ but maybe not, without going through the html source I dunno how that demo works, or if it uses technology that can be used from cc's http api

#8 1v2

  • Members
  • 89 posts
  • LocationAmsterdam

Posted 12 October 2012 - 07:36 PM

Interesting.

#9 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 12 October 2012 - 08:11 PM

View PostGopherAtl, on 12 October 2012 - 07:30 PM, said:

until/unless someone ports it, you can't use it in cc. You can only use it outside cc to compile moonscript programs into lua programs for use in CC.

:edit: or, it might be possible to use this web demo with the http api http://moonscript.org/compiler/ but maybe not, without going through the html source I dunno how that demo works, or if it uses technology that can be used from cc's http api
I've actually been meaning to make a moonscript compiler for CC

Not really a full compiler, just to steal some of it's features - I didn't intend on adding the ability of being able to omit ends, thens and dos, but I wanted to add simple stuff, like ! function calling and assignment operators.

#10 ETHANATOR360

  • Members
  • 423 posts
  • Locationyour hardrive

Posted 12 October 2012 - 08:32 PM

cool

#11 toxicwolf

  • Members
  • 201 posts
  • LocationUnited Kingdom

Posted 13 October 2012 - 09:56 AM

Yeah, when you said that you had written stuff in CC using moonscript, I assumed that you meant that there was some level of moonscript compiler that could be installed into CC. It would be brilliant if someone could make one (I obviously don't have the skill/knowledge or I would try to myself), since it seems a really nice combination of programming languages.

#12 toxicwolf

  • Members
  • 201 posts
  • LocationUnited Kingdom

Posted 15 October 2012 - 09:22 PM

Looking at the source code, could you not use the moonscript module by loading it into one big API? For example the source code references things such as 'moonscript.init', so int would be a subtable loaded into the moonscript API and loaded from the init.lua file in the sourcecode. I'm sure there must be a function that uses the rest of the module to directly parse/compile moonscript strings to lua ones.

#13 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 18 October 2012 - 09:19 PM

View Posttoxicwolf, on 15 October 2012 - 09:22 PM, said:

Looking at the source code, could you not use the moonscript module by loading it into one big API? For example the source code references things such as 'moonscript.init', so int would be a subtable loaded into the moonscript API and loaded from the init.lua file in the sourcecode. I'm sure there must be a function that uses the rest of the module to directly parse/compile moonscript strings to lua ones.
That is a very good point, I never thought about that.

I'll be right back.

EDIT: Well, I attempted to write a compiler, but the "require" function doesn't even exist in CC apparently, which basically breaks the entire thing.

Time to keep waiting until someone remakes a compiler XD





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users