Lesson 1 of 8

Hello, Lua

Write your first Lua program and learn and basic types. Lua has a small syntax, so it is a comfortable place to start if you are new to programming.

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 , which is the classic source of Lua .

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)
Finished reading?Mark it done to track your progress.

Tip: use the ← and → keys to move between lessons.