Introduction
Lua is a lightweight, fast, embeddable scripting language used to control and extend larger programs such as Roblox, Neovim, and Redis.
Part of the free Lua course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
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.
What You'll Learn
💡 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.
Notice 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.
4. 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.
5. 🎯 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.
Next, practise the concatenation operator and a block comment in one go:
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: " .. 99 actually works (Lua converts the number for you), but "Score: " .. nil errors. If a value might be missing, give it a default first.
- Forgetting local makes a global: writing name = "Sam" without local still runs, but it creates a global variable that any other code can overwrite by accident. You'll learn to always prefer local in 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 , not 0 like 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
--[[ ... ]]
Join text
"a" .. "b"
ab
Local variable
local name = "Ada"
Ada
Frequently Asked Questions
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.
🎉 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 lua command locally
- ✅ Next lesson: Variables and Data Types — local , numbers, booleans, nil , and the all-important table
Practice quiz
How do you display text in the console in Lua?
- print("Hi")
- echo("Hi")
- console.log("Hi")
- write("Hi")
Answer: print("Hi"). print() is the built-in function that shows values on screen.
Which operator joins (concatenates) two strings in Lua?
- +
- ..
- &
- concat
Answer: ... Lua uses .. (two dots) to concatenate; + is only for numbers.
How do you start a single-line comment in Lua?
- //
- #
- --
- /*
Answer: --. Two dashes -- begin a single-line comment in Lua.
Which keyword makes a variable local to its block?
- var
- let
- const
- local
Answer: local. local declares a block-scoped variable; without it the variable is global.
What does print("a", "b") put between the values?
- A tab character
- A space
- A comma
- Nothing
Answer: A tab character. print separates multiple arguments with a tab.
What happens if you write name = "Sam" without local?
- A syntax error
- It creates a global variable
- It does nothing
- It creates a constant
Answer: It creates a global variable. Bare assignment creates a global variable in Lua.
How do you write a block (multi-line) comment in Lua?
- /* ... */
- ### ... ###
Block comments are wrapped in --[[ and ]].
What does "Lua" mean in Portuguese?
- Light
- Fast
- Script
- Moon
Answer: Moon. Lua means moon in Portuguese.
Why does print("Hi " + name) fail in Lua?
- + is only for numbers, not joining text
- name is undefined
- print takes one argument
- Strings need single quotes
Answer: + is only for numbers, not joining text. In Lua + does arithmetic; joining text needs .. instead.
Which Roblox dialect of Lua powers Roblox game logic?
- LuaJIT
- Luau
- MoonScript
- Terra
Answer: Luau. Roblox uses Luau, its own dialect of Lua.
Continue this course
- Next: Variables and Data Types