Lua Tutorial:

Lua Metatables


  • [[local] mt = ]getmetatable(t) --> retrieve associated metatable for 't'
  • [[local] t = ]setmetatable(t, mt) --> set the metatable for 't' to 'mt' and returns 't'


tVariable referring to a lua table; can also be a table literal.
mtTable to use as a metatable; can have zero or more metamethod fields set.


There are some metamethods not mentioned here. For the full list and their usage, see the corresponding entry in the lua manual.

Lua Metatables Examples:

Related Lua Tutorial Topics:

Other Tutorial Topics:

This modified content is an extract of the original Stack Overflow Documentation released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow. This topic was created and modified by the Stack Ovedrflow Contributor.