Skip to content
AgileLogics
4 min read

Your First Program

Prerequisites: Installing Lua

Create a file named hello.lua:

print("Hello, world!")
print("Welcome to Lua.")

Run it:

lua hello.lua

Expected output

Hello, world!
Welcome to Lua.
  • print writes its arguments to the screen, followed by a new line.
  • Strings go in double or single quotes — both work the same.
  • No semicolons, no main function: Lua runs a file from top to bottom.

print with several values

print("Answer:", 42)
print(1, 2, 3)
print("no tab " .. "here")
Answer:	42
1	2	3
no tab here

print separates several arguments with a tab. To join text without a gap, use .. (the concatenation operator).

io.write

io.write("Loading")
io.write("...")
io.write(" done\n")
Loading... done

io.write prints exactly what you give it — no tabs, no newline — which is useful for building a line in pieces.

Practice

Write a program that prints your name on one line and your favorite food on the next.

Show solution
print("Ada")
print("Pizza")
Ada
Pizza