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): anyParameters
| Parameter | Type | Description |
|---|---|---|
value | any | Value whose metatable is read. |
field | string | Field name. |
Example
local subject = setmetatable({}, { __index = function() return 1 end, __metatable = "locked" })
print(type(getmetafield(subject, "__index")), getmetafield(subject, "__len"))Example output
function nil