getmetafield Synchronous

Read one field directly from an object’s raw metatable. It is useful when you only need to inspect a specific metamethod without walking the whole table.

Syntax
Luau
getmetafield(value: any, field: string) -> any

Parameters

Function parameters
ParameterTypeDescription
valueanyValue with a metatable.
fieldstringField name, such as "__index".

Returns

any

The raw field value, or nil when the field or metatable is absent.

Example

Example
Luau
local object = setmetatable({}, { __tostring = function() return "item" end })
print(type(getmetafield(object, "__tostring"))) -- function
Kawaii documentation