MoonScript: Lua, but nicer.

MoonScript is a wonderful scripting language based off of Lua, but with a few odd but interesting changes. It’s based mainly off of CoffeeScript, and it borrows a couple of concepts from other languages like Python and Ruby. Of course, printing “hello world” in both languages is the same, but if you wanted to, say, double every odd number in a list, this is what you would do in MoonScript:

numbers = {1, 2, 3, 4, 5}
doubledOdds = [num * 2 for num in *numbers when num % 2 == 1]

And in Lua:

numbers = {1, 2, 3, 4, 5}
doubledOdds = {}

for i=1, #numbers do
  num = numbers[i]
  if num % 2 == 1 then
    num = num * 2
  end
  doubledOdds[i] = num
end

The difference between which language is easier to use should be pretty clear here. It’s all a matter of preference, though, and I still like lua a lot, because without lua, there would be no moonscript! (or love2d, or computercraft, etc.)

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s