Your first program
A Lua program is just a text file of instructions that print, calculate and decide.
In this page:
Your first program
A Lua script is a plain text file, usually ending in .lua, run from top to bottom. The function print writes its arguments to the screen followed by a newline. Strings are written between quotes and joined with the .. operator.
Note:
Save scripts with the .lua extension so editors recognise them.
Example: Your first program
local name = "World"
print("Hello, " .. name .. "!")
print("2 + 3 =", 2 + 3)
-- Output:
-- Hello, World!
-- 2 + 3 = 5
Login to try C/C++/Java/PHP code in the editor
Common Mistakes
- Forgetting the parentheses after print in a call with several arguments
- Using + instead of .. to join strings
- Mismatching the opening and closing quotes
Chapter Summary
- A script runs from top to bottom
- print adds a newline
- Strings use single or double quotes
- .. joins strings
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: