Metatables

getmetafield

Reads a field from a target metatable without changing readonly state.

Syntax

getmetafield(target: any, field: string): any | nil

Arguments

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

Returns

NameTypeDescription
fieldValueany | nilMetatable field value, or nil when absent.

Description

Reads a field from a target metatable without changing readonly state.

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 fieldValue (any | nil). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Example call with placeholder values.

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