Hello World in MoonScript

Published on 01 November 2018 (Updated: 02 November 2018)

Hello World in MoonScript

In this article, we’ll cover Hello World in MoonScript, a niche scripting language that compiles to Lua.

How to Implement the Solution

As you can see here, Hello World in MoonScript has a relatively simple implementation:

print "Hello, World!"

All we have to do is call the built-in Lua function print, and that’s it. Behind the scenes, the code is compiled into Lua which is, in this case, exactly the same.

In other cases, it could be different. For instance, we could have an implementation of some arithmetic which we print to the user:

x = 10
y = 15
z = x + y
print y

The code is then compiled into Lua like this:

local x = 10
local y = 15
local z = x + y
return print(y)

How cool is that?1

How to Run the Solution

If your feeling adventurous today, You can quickly install MoonScript using one of the following methods:

For Windows users, you can try installing the windows binaries.

For Linux users, install LuaRocks which is a package manager for Lua modules. Then run the following command:

luarocks install moonscript

With the moon executable and Lua modules on your device, run your .moon file with this command:

moon ./YOURFILE.moon

Also, you can compile your .moon file into Lua by using this command:

moonc ./YOURFILE.moon

Alternatively, you can always run MoonScript using an online compiler.1


  1. B. Mohamed, “Hello World in MoonScript,” The Renegade Coder, 02-Sep-2018. [Online]. Available: https://therenegadecoder.com/code/hello-world-in-moonscript/. [Accessed: 31-Oct-2018].  2