metatables
Provides a wide range of APIs to interact with metatables in a myriad of ways.
Types
metafield
Typetype
metafield =
"__index"
|
"__newindex"
|
"__mode"
|
"__namecall"
|
"__call"
|
"__iter"
|
"__len"
|
"__eq"
|
"__add"
|
"__sub"
|
"__mul"
|
"__div"
|
"__idiv"
|
"__mod"
|
"__pow"
|
"__unm"
|
"__lt"
|
"__le"
|
"__concat"
|
"__type"
All possible metafields in Luau.
Functions
getrawmetatable
metatables.
getrawmetatable
(
object:
T
--
The object to get the metatable of.
) →
{
[
metafield
]
:
any
}
|
nil
--
The metatable of the object.
Returns the metatable of the given object, even if the __metatable
metafield is set.
Hooking
This function should never be used to perform metatable hooks. Use metatables.hookmetamethod
instead.
setrawmetatable
metatables.
setrawmetatable
(
object:
T
,
--
The object to get the metatable of.
) →
{
[
metafield
]
:
any
}
|
nil
--
The previous metatable of the object (if it had any).
Sets the metatable of object
and returns the previous metatable of it..
getmetafield
metatables.
getmetafield
(
object:
T
,
--
The object with a metatable to get the metafield of.
) →
U
--
The metafield of the object.
Returns the metafield (if existing) of the metatable the object has.
Errors
Type | Description |
---|---|
invalid metafield | The metatable is invalid (bad metafield name) |
no metatable found | No metatable was found on the given object. |
no metafield found | No metafield was found on the given object's metatable. |
hasmetafield
metatables.
hasmetafield
(
object:
T
,
--
The object to check.
) →
boolean
--
If true, the object has the metafield.
Checks if the given object has a specific metafield.
Errors
Type | Description |
---|---|
invalid metafield | The metatable is invalid (bad metafield name) |
no metatable found | No metatable was found on the given object. |
hasmetatable
metatables.
hasmetatable
(
object:
T
--
The object to check.
) →
boolean
--
If true, the object has a metatable.
Checks if the given object has a metatable.
isreadonly
metatables.
isreadonly
(
object:
{
[
any
]
:
any
}
--
The table to check.
) →
boolean
--
If true, the table is read-only.
Checks if the the given table is marked as read-only.
Usage
Normally used on metatables to allow modifying the table, but works on any table, regardless if they're a metatable or not,
hookmetamethod
metatables.
hookmetamethod
(
object:
T
,
--
The object to hook.
callback:
(
U...
)
→
O...
--
The callback to hook the metamethod with.
) →
(
U...
)
→
O...
--
The original metamethod
Hooks the given object's metatable metamethod with the provided callback.
Implementation
This function must contain an argument guard which controls that the function is given the correct number of arguments. This function should use a form of hookfunction
to hook, and most NOT replace the metatable's metamethods directly.
Argument Guard
You may disable the integrated argument guard by using a vararg
function. This dismisses stack size checks (it is up to you to make sure the correct number of arguments are obtained).
Hookfunction
This function may inherit errors and warnings from hookfunction
.
Errors
Type | Description |
---|---|
invalid metafield | The metatable is invalid (bad metafield name) |
no metatable found | No metatable was found on the given object. |
no metafield found | No metafield was found on the given object's metatable. |
metafield is not a function | The metafield is not implemented as a function, but as a property. |
restoremetamethod
metatables.
restoremetamethod
(
object:
T
,
--
The object with the metatable and metamethod to restore.
) →
(
)
Restores a metamethod hooked with hookmetamethod
.
restorefunction
This function may inherit errors and warnings from restorefunction
!
Errors
Type | Description |
---|---|
invalid metafield | The metatable is invalid (bad metafield name) |
no metatable found | No metatable was found on the given object. |
no metafield found | No metafield was found on the given object's metatable. |
metafield is not a function | The metafield is not implemented as a function, but as a property. |