AcediaDocumentation

getmetafield

Reads one field out of a value's raw metatable.

Returns nil when the value has no metatable or the metatable has no such field. The lookup is raw on both counts: a __metatable field does not hide the table, and a __index on the metatable is not consulted.

getmetafield(value: any, field: string): any

Parameters

ParameterTypeDescription
valueanyValue whose metatable is read.
fieldstringField name.

Example

local subject = setmetatable({}, { __index = function() return 1 end, __metatable = "locked" })
print(type(getmetafield(subject, "__index")), getmetafield(subject, "__len"))

Example output

function nil

On this page