Syntax
hasmetatable(target: any): booleanArguments
| Name | Type | Description |
|---|---|---|
target | any | Value to check for a metatable. |
Returns
| Name | Type | Description |
|---|---|---|
hasMetatable | boolean | true when the target has a metatable; otherwise false. |
Description
Returns whether the target value has a metatable. The function returns one boolean and does not return or change the metatable itself.
Call it with 1 parameter(s): target. The argument table explains which values are required and which ones only refine the behavior.
It returns hasMetatable (boolean). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Check whether a value currently has a metatable.
local target = {}
print(hasmetatable(target))
setrawmetatable(target, {})
print(hasmetatable(target))