Introduction

Lua is a lightweight, fast, embeddable scripting language used to control and extend larger programs such as Roblox, Neovim, and Redis.

Learn Python, JavaScript, Java and more with free interactive lessons, real projects and AI-powered help. Beginner-friendly.

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.

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:

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:

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.

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.

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.