LuLua · Lesson 1 of 8

Hello, Lua

Lua's entire syntax fits on a postcard. If you've never programmed before, this is one of the gentlest starts there is.

Lua
-- hello.lua  (-- starts a comment)
print("Hello, World!")

local name = "Ada"        -- 'local' declares a variable
local age = 17
print("I'm " .. name)     -- .. joins strings
print(name, age)          -- print takes many values

--[[ This is a
     multi-line comment ]]

No semicolons, no braces, no type declarations. Variables are declared with local — and you should always use it. Assigning without local creates a global variable, which is the classic source of Lua bugs.

Lua
-- Lua has exactly 8 types. The ones you'll use daily:
local n = 42              -- number (integers and floats)
local pi = 3.14159        -- also number
local s = "text"          -- string
local ok = true           -- boolean
local nothing = nil       -- nil: the absence of a value

print(type(n))            -- "number"
print(10 / 3)             -- 3.3333... (real division)
print(10 // 3)            -- 3 (floor division)
print(2 ^ 10)             -- 1024 (power)
print(#"hello")           -- 5 (# is length)
⚠ Warning
Forget 'local' and the variable becomes global — visible and mutable from everywhere, including other files. Make writing 'local' muscle memory now.