luametatable

Lua: Is there a way to get a tables metatable


Is there a way to get a tables metatable? e.g.

local tbl = {}
setmetatable(tbl, {__call = function() print("tbl called") end})

-- how to get metatable of tbl?

Solution

  • You can use getmetatable(tbl) to get the assigned metatable (or nil if none is assigned).