Lua is small on purpose. The whole interpreter is about 32,000 lines of C and compiles down to a few hundred kilobytes. That number is not trivia — it is the reason you keep running into Lua. It is cheap enough to drop inside another program, so that is where it usually lives.
Places you have probably already used Lua without knowing: Roblox (its Luau language is a Lua dialect), World of Warcraft addons, the Neovim text editor, and LÖVE, the game framework you will use in Unit 2.
The name is not an acronym. Lua means "moon" in Portuguese — it was created at PUC-Rio in Brazil, and it is pronounced LOO-ah.
One consequence of being small: you can actually finish learning it. That is not true of most languages, and it is most of why this course exists.
print writes a line to the terminal. It is the whole of your output toolkit for now.
print("Hello, Lua!")Hello, Lua!You run a Lua file by handing it to the interpreter. From a terminal in the same folder as your file:
lua main.luaTwo dashes start a comment. Lua reads to the end of the line and ignores all of it. For several lines at once, use --[[ ]].
-- Lua ignores this line.
--[[ And every line inside this block.]]
print("Only this line runs.")Only this line runs.print takes as many values as you give it, of any type, separated by commas. Watch the spacing carefully — this catches people.
print("Ada", 42, true)print("Ada" .. " " .. "42")Ada 42 trueAda 42Commas insert a tab, not a space. If you want exact control over the spacing, join the pieces yourself with .., which is Lua's way of gluing two strings together. Activity 1.3 is all about that operator.
Make a folder for this course, and inside it create a file named main.lua. You will run it after every task — getting into that habit now is worth more than anything else on this page.
lua main.lua before you write anything else.print("SKYNEST TERMINAL")SKYNEST TERMINAL-- main.lua - Skynest terminal readout
print("SKYNEST TERMINAL")print("----------------")SKYNEST TERMINAL----------------The comment produced nothing, which is the entire point of it.
print call, separated by commas.-- main.lua - Skynest terminal readout
print("SKYNEST TERMINAL")print("----------------")print("Status:", "ONLINE")print("Reactor:", 98, "percent")print("Crew:", 4)Status: ONLINE with a single space instead of a tab. You will need .. and one print call.Running your finished file should produce this.
SKYNEST TERMINAL----------------Status: ONLINEReactor: 98 percentCrew: 4If you got an error instead, read the line number it gives you and check that every string has both of its quotes. Lua's error messages are short, and they are usually pointing at the right line.