hasmetatable
Returns true when the object has a metatable.
Syntax
hasmetatable(object: any) -> boolean
Parameters
| Parameter | Type | Description |
|---|---|---|
object | any | The object value used by the call. |
Returns
| Type | Description |
|---|---|
boolean | True when the object has a metatable |
Description
hasmetatable is part of the Metatables library. Metatable helpers operate below normal Lua protection: they read raw metatables, replace metamethods and inspect namecalls.
The call is a predicate: it inspects the current state and returns a boolean without modifying anything.
Example
print(hasmetatable(setmetatable({}, {}))) -- true
Notes
- Metatable changes are applied directly to the live object.