Hello World in MoonScriptPublished on 01 November 2018 (Updated: 02 May 2020)
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?
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:
Also, you can compile your .moon file into Lua by using this command:
Alternatively, you can always run MoonScript using an online compiler.
- Hello World in MoonScript on The Renegade Coder