getmetatable()

Type Function
Library (globals)
Return value Table
Revision 2017.3060
Keywords getmetatable, setmetatable, metatables, tables
See also setmetatable()

Overview

Gets the metatable of a specified Table. If the table does not have a metatable, it returns nil. Otherwise, if the object's metatable has a __metatable field, it returns the associated value. Otherwise, it returns the metatable of the given table.

Syntax

getmetatable( object )
object (required)

Table. A table for which to get the metatable.

Example

local t = {}
t.name = "Joe"

local mt = {}
setmetatable( t, mt )

local another_t = {}
setmetatable( another_t, getmetatable(t) )