AcediaDocumentation

hasmetafield

Checks whether a value's raw metatable defines a field.

Answers the same question as getmetafield returning a non-nil value, without handing the field itself to the caller.

hasmetafield(value: any, field: string): boolean

Parameters

ParameterTypeDescription
valueanyValue whose metatable is read.
fieldstringField name.

Example

local subject = setmetatable({}, { __index = {} })
print(hasmetafield(subject, "__index"), hasmetafield(subject, "__call"))

Example output

true false

On this page