getmetafield
Returns a field from an object's raw metatable.
Syntax
getmetafield(object: any, key: string) -> any
Parameters
| Parameter | Type | Description |
|---|---|---|
object | any | The object value used by the call. |
key | string | The key or secret used by the operation. |
Returns
| Type | Description |
|---|---|
any | A field from an object's raw metatable |
Description
getmetafield 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 read-only: it resolves the current value when invoked and does not change the underlying state.
Example
local object = setmetatable({}, { __index = function() return 1 end })
print(getmetafield(object, "__index") ~= nil)
Notes
- Metatable changes are applied directly to the live object.