Syntax
local vector = setmetatable({ x = 0, y = 0 }, Vector)Examples
Lua setmetatable example
A focused example you can adapt while practising.
local vector = setmetatable({ x = 0, y = 0 }, Vector)Best practices
- Start with the smallest working example, then adapt it to your project.
- Use the language’s standard library and idioms before introducing extra dependencies.
At a glance
- Purpose
- Lightweight scripting and embedding
- File extension
- .lua
- Runs in
- Lua interpreter or a host application
- Usually used with
- Host APIs and Lua modules
Specifications & further reading
Related Lua documentation
Lua Tables
Tables are Lua’s main compound data structure. They can act as arrays, dictionaries, objects, and namespaces; indexes begin at 1 by convention for sequences.Lua array-style tables
Lua reference for lua array-style tables.Lua keyed tables
Lua reference for lua keyed tables.Lua table.insert and remove
Lua reference for lua table.insert and remove.
Tables are Lua’s main compound data structure. They can act as arrays, dictionaries, objects, and namespaces; indexes begin at 1 by convention for sequences.Lua array-style tables
Lua reference for lua array-style tables.Lua keyed tables
Lua reference for lua keyed tables.Lua table.insert and remove
Lua reference for lua table.insert and remove.