hasmetafield Synchronous

Check whether an object’s raw metatable defines a non-nil field. Use it before taking a path that depends on a particular metamethod.

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

Parameters

Function parameters
ParameterTypeDescription
valueanyValue to inspect.
fieldstringField name to test.

Returns

boolean

true if the raw metatable field is non-nil.

Example

Example
Luau
local object = setmetatable({}, { __index = function() end })
print(hasmetafield(object, "__index")) -- true
Kawaii documentation