Hello World in Lua
Your first Lua program - the classic Hello World example with Docker setup
Lua is designed to be simple, and Hello World demonstrates this beautifully. In Lua, printing to the console is just one line—no imports, no classes, no boilerplate.
The Code
Create a file named hello.lua:
| |
That’s it. One line, one function, one string. This simplicity is intentional—Lua was designed to be learnable in hours, not days.
Understanding the Code
print()- A built-in function that outputs text to the standard output"Hello, World!"- A string literal enclosed in double quotes- No semicolons - Statement terminators are optional in Lua (newlines work)
- No includes needed -
printis available in the global scope by default
Running with Docker
The easiest way to run Lua without installing it locally:
| |
Running Locally
If you have Lua installed on your system:
| |
Expected Output
Hello, World!
Alternative Syntax
Lua offers several ways to write strings and call functions:
| |
All of these produce the same output!
Key Concepts
- Lua is interpreted - No compilation step; the interpreter reads and executes source directly
- Dynamic typing - Variables don’t have fixed types
- Automatic memory management - Lua handles garbage collection
- 1-indexed arrays - Unlike most languages, Lua arrays start at index 1
- Tables everywhere - Almost everything in Lua is built on tables
Interactive Mode (REPL)
Lua has an interactive mode for experimentation:
| |
Then type:
| |
The > prompt indicates you’re in the Lua REPL (Read-Eval-Print Loop).
Why Lua for Beginners?
| Feature | Benefit |
|---|---|
| Minimal syntax | Less to memorize |
| No type declarations | Focus on logic, not types |
| Fast feedback | Interpreted, no compile step |
| Small standard library | Less overwhelming |
| Consistent rules | Few edge cases |
A Slightly Longer Example
Here’s a preview of what’s coming in future tutorials:
| |
Next Steps
Continue to Variables and Data Types to learn about Lua’s type system and how to store and manipulate data.
Running Today
All examples can be run using Docker:
docker pull nickblah/lua:5.4-alpine