Lesson 1 • Beginner Track
Introduction to Lua
By the end of this lesson you'll know exactly what Lua is and why it powers Roblox, Neovim, and Redis — and you'll have written, commented, and run your own first Lua program.
hello.lua, and type lua hello.lua.What You'll Learn
- Explain what Lua is and why it's lightweight, fast, and embeddable
- Name real products that run on Lua (Roblox, Neovim, Redis, WoW addons)
- Print text to the screen with print()
- Write single-line (--) and block (--[[ ]]) comments
- Join text together with the .. concatenation operator
- Run a Lua script online or with the lua command in a terminal
💡 Real-World Analogy
Think of Lua as the engine you drop into someone else's car. Big programs — a game engine, a database, a text editor — are the car: the body, wheels, and dashboard. They handle the heavy machinery but need something small and nimble to tell them what to do. That's Lua. It's deliberately tiny so it can be embedded inside those bigger programs and "script" their behaviour. When you change a Roblox game's rules, configure Neovim, or speed up Redis, you're writing Lua that steers a much larger program — without rebuilding the whole car.
1. What Is Lua?
Lua (meaning "moon" in Portuguese, pronounced LOO-ah) is a lightweight, fast, embeddable scripting language created in 1993 at the Pontifical Catholic University of Rio de Janeiro. A scripting language is one you use to control or extend a program that already exists, rather than to build that program from the ground up. "Embeddable" means Lua is designed to live inside another application — it's tiny (the whole interpreter is a few hundred kilobytes) and one of the fastest scripting languages there is.
Because it's so small and quick, Lua became the go-to language for adding scripting to large software. You're almost certainly using something powered by Lua already:
Where Lua Runs in the Real World
- Roblox — every game's logic is written in Luau, Roblox's Lua dialect
- Neovim — modern config and plugins are written in Lua
- Redis — runs Lua scripts server-side for fast, atomic database operations
- World of Warcraft — UI addons and macros are Lua
- Game engines — LÖVE2D, Defold, and many studios embed Lua for gameplay
- Nginx / OpenResty — high-performance web request handling in Lua
The lesson: learning Lua isn't academic. The same print() and .. you're about to use are exactly what Roblox developers and Neovim users type every day.
2. Your First Program: print()
Lua has no boilerplate — no imports, no main function, no setup. A Lua program is just a text file (usually ending in .lua), and Lua runs it from the first line down. The one function you need on day one is print(), which displays whatever you give it on the screen. Read this worked example, then run it yourself.
-- Your very first Lua program.
-- "--" starts a comment: Lua ignores everything after it on the line.
print("Hello, World!") -- print() shows text in the terminal
-- print() can take more than one value, separated by commas.
-- Lua puts a TAB between them.
print("Lua", "is", "fun") -- prints: Lua is fun
-- prints:
-- Hello, World!
-- Lua is funNotice there's no ceremony: print("Hello, World!") on its own is a complete, runnable program. The text inside "double quotes" is called a string — that's just the programming word for "a piece of text".
3. Comments: Notes Lua Ignores
A comment is a note for humans that Lua skips over completely. You use comments to explain why code does something, or to temporarily switch a line off without deleting it. Lua has two kinds: a single-line comment starts with -- (two dashes) and runs to the end of the line, and a block comment is wrapped in --[[ and ]] and can span many lines.
-- A single-line comment starts with two dashes.
print("This line runs") -- a comment can also sit after code
-- print("This line does NOT run") -- it's commented out
--[[
This is a block (multi-line) comment.
Everything between the double brackets is ignored,
which is handy for notes or temporarily disabling code.
]]
print("Done")
-- prints:
-- This line runs
-- Done4. Joining Text with ..
Often you want to build a message out of pieces — a fixed greeting plus a name, for example. Lua glues strings together with the concatenation operator .. (two dots with spaces around them). This is a key difference from many languages: in Lua, + is only for adding numbers, and .. is only for joining text. Here's a small but complete first program that uses a variable and concatenation together.
-- A tiny but complete program: greet a person by name.
-- "local" makes a variable that lives only in this file/block.
local name = "Ada" -- a string: text wrapped in quotes
-- ".." is Lua's concatenation operator — it GLUES strings together.
-- (Most languages use "+", but in Lua "+" is only for numbers.)
print("Hello, " .. name .. "!") -- prints: Hello, Ada!
-- You can also pass the pieces to print() with commas, but then
-- you get tabs between them instead of a clean join:
print("Hello,", name) -- prints: Hello, Ada
-- prints:
-- Hello, Ada!
-- Hello, Ada5. 🎯 Your Turn
Time to write some Lua yourself. Each program below is almost finished — replace the ___ blanks using the -- 👉 hints, then run it at onecompiler.com/lua and check your output against the -- ✅ Expected output comment.
-- 🎯 YOUR TURN — replace each ___ then run this at onecompiler.com/lua
-- 1) Print the exact text: I am learning Lua
print(___) -- 👉 put the text in "double quotes"
-- 2) Print your favourite game on its own line
print(___) -- 👉 e.g. "Roblox"
-- ✅ Expected output (example):
-- I am learning Lua
-- RobloxNext, practise the concatenation operator and a block comment in one go:
-- 🎯 YOUR TURN — build a greeting by gluing strings together.
local name = "Sam"
-- 1) Use .. to join "Hi, " then name then "!" into one line.
print("Hi, " ___ name ___ "!") -- 👉 each ___ is the .. operator
-- 2) Add a block comment below describing what this program does.
___ -- 👉 start with --[[ and end with ]]
-- ✅ Expected output:
-- Hi, Sam!Pro Tip
Lua's entire standard library fits in your head — there are only about 30 built-in functions. That simplicity is a feature, not a limitation: it's exactly why Lua is so easy to learn and so quick for big programs to embed.
Common Errors (and the fix)
- Using
+to join text:print("Hi " + name)throws "attempt to perform arithmetic on a string value". In Lua, joining text is.., not+:print("Hi " .. name). - Concatenating a number without converting: mixing types like
"Score: " .. 99actually works (Lua converts the number for you), but"Score: " .. nilerrors. If a value might be missing, give it a default first. - Forgetting
localmakes a global: writingname = "Sam"withoutlocalstill runs, but it creates a global variable that any other code can overwrite by accident. You'll learn to always preferlocalin the next lesson — Lua makes variables global by default, which surprises newcomers. - Expecting lists to start at 0: a quick heads-up for later — Lua tables (its lists) are 1-based, so the first item is at index
1, not0like most languages. Keep it in mind; you'll meet tables soon. - Closing a block comment wrong: a
--[[must be ended with]]. Leave it open and Lua treats the rest of your file as a comment, so nothing runs.
Quick Reference
| Task | Code | Result |
|---|---|---|
| Print text | print("Hello") | Hello |
| Print several values | print("a", "b") | a b |
| Single-line comment | -- note here | (ignored) |
| Block comment | --[[ ... ]] | (ignored) |
| Join text | "a" .. "b" | ab |
| Local variable | local name = "Ada" | Ada |
Frequently Asked Questions
Q: Is Lua hard to learn for a complete beginner?
Lua is one of the easiest languages to start with. The whole language is tiny — there are only about 30 built-in functions and a handful of keywords — so you can hold most of it in your head. You'll write a working program in your first hour.
Q: Do I need to install anything to run Lua?
Not necessarily. You can run every example in this lesson for free in your browser at onecompiler.com/lua or lua.org/demo. When you're ready, install Lua locally from lua.org/download and run scripts with the 'lua' command.
Q: Why does Lua use .. for joining text instead of +?
In Lua, + is strictly for arithmetic on numbers, and .. (two dots) is strictly for concatenating strings. Keeping them separate avoids the confusion some languages have where + means both 'add' and 'join' depending on the values.
Q: Is the Lua I learn here the same as Roblox's Luau?
Yes — Luau is Roblox's dialect of Lua. Everything in this lesson (print, comments, variables, concatenation) works identically in Luau. Luau just adds extra features like type annotations on top, so what you learn here transfers directly.
Mini-Challenge: Your Business Card
No blanks this time — just a brief and an outline to keep you on track. Write the whole thing yourself, run it, and check your output against the example in the comments. This is the kind of tiny, self-contained script real projects are full of.
-- 🎯 MINI-CHALLENGE: a one-line "business card"
-- 1. Make a local variable "name" (your name, in quotes)
-- 2. Make a local variable "role" (e.g. "Lua Learner")
-- 3. Use print() and .. to show: name .. " — " .. role
-- 4. BONUS: add a block comment at the top explaining the script
--
-- ✅ Expected output (example):
-- Ada — Lua Learner
-- your code here🎉 Lesson Complete
- ✅ Lua is a lightweight, fast, embeddable scripting language used in Roblox, Neovim, Redis, and game engines
- ✅
print()shows text on screen — and a Lua file runs top to bottom with no boilerplate - ✅ Comments are notes Lua ignores:
--for one line,--[[ ]]for many - ✅
..joins strings together (and+is only for numbers) - ✅ You can run Lua free online or with the
luacommand locally - ✅ Next lesson: Variables and Data Types —
local, numbers, booleans,nil, and the all-important table
Sign up for free to track which lessons you've completed and get learning reminders.