Lua Introduction
Lua is a small scripting language. It runs inside other programs, such as games and tools, and it also runs on its own.
One print shows one line
The print command takes a value and shows it. The words inside the quotes appear on the screen.
print("Hello, Lua!")Two prints run in order
Each print adds its own line to the screen. The lines appear in the same order as the prints in the script.
print("Loading game")
print("Game ready")Text and a number in one print
One print can show several values at once. Lua leaves a tab gap between the values.
print("Score", 100)Example
print("Game Status")
print("Player", "Sam")
print("Lives", 3)
print("Level", 1)Key points
- Script: a text file that holds instructions for the computer.
- print: a command that shows values on the screen.
- Embedded use: Lua often runs inside a larger program, such as a game.
- Standalone use: Lua can also run on its own as a plain script.
- Order: the lines of a script run from top to bottom.
In this example, four print lines build a small game status report. The first print shows the title on its own line. The next three prints each show a label and a value, split by a tab.
Note
Lua is small, so it fits easily inside other programs.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does print do in a Lua script?