Metatables

hasmetafield

Checks whether a metatable contains a field.

Syntax

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

Arguments

NameTypeDescription
targetanyTarget function, table, stack level, or object being inspected or changed.
fieldstringMetatable field name to inspect.

Returns

NameTypeDescription
hasFieldbooleanTrue when the metatable contains the requested field.

Description

Checks whether a metatable contains a field.

Call it with 2 parameter(s): target, field. The argument table explains which values are required and which ones only refine the behavior.

It returns hasField (boolean). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Example call with placeholder values.

local result = hasmetafield(nil, "example")
print(result)