Introduction to Lua

New to Lua itself, not just to Luak? Start here. This section assumes no prior Lua experience, only general programming familiarity.

What Lua is

Lua is a small, dynamically typed scripting language, designed from the start to be embedded inside a host application rather than run on its own. It has been the scripting layer under countless games, tools and applications since 1993. A few things fall out of that design goal:

  • The whole language is tiny: the reference manual is short enough to read in an afternoon.
  • It has no built-in notion of files, networking or a screen: those come from whatever embeds it.
  • It is forgiving about types: variables do not have declared types, values do.

Hello, world

A Lua program is just a sequence of statements. There is no main function to define.

print("hello, world")

You can run that right now in the Playground, no install required.

The shape of the syntax

A few things to orient yourself before the rest of this section:

  • Statements do not need a terminator, no semicolons required, though ; is legal as a separator if you want one.
  • Blocks (the body of a function, an if, a loop) are closed with the keyword end, not braces.
  • Comments start with --. A block comment is --[[ ... ]].
  • Lua is case-sensitive, and keywords like end, if, local are reserved: they cannot be used as variable names.
  • Indexing is 1-based, not 0-based. This trips up almost everyone coming from C-family languages at least once.
-- a single-line comment

--[[
    a block comment,
    spanning multiple lines
]]

local name = "Luak"
print("Hello from " .. name)