object’s metatable, redirecting it to hook. Returns a
callable for the original metamethod so you can forward to it. This is the
targeted, safe way to intercept behavior like __index, __namecall, or
__newindex on a specific object’s metatable.
Parameters
any
required
The value whose metatable carries the metamethod. It must have a metatable.
string
required
The metamethod name, e.g.
"__index", "__namecall", "__newindex".function
required
The replacement metamethod.
boolean
default:"true"
Accepted for compatibility with other executors and ignored. Athena reads
no behavior from this argument. Pass it or omit it; the result is the same.
Filter
An optional filter. When given,
hook runs only for calls
the filter matches; every other call goes straight to the original metamethod.
The filter is evaluated natively, so non-matching calls never enter Luau.Returns
function
A function that invokes the original metamethod. Call it to forward.
Behavior
- Readonly metatables are handled. Game metatables are typically readonly;
hookmetamethodrecords what it changed sorestoremetamethodandrestorefunctioncan both undo it, without leaving the metatable writable. - The metamethod must already be a function. Hooking a metamethod that is not a function (or absent) is rejected.
- Pair with
checkcaller. Inside the hook, usecheckcallerto separate the game’s calls from your own and forward the rest unchanged.
Example
Intercept remote calls via__namecall:
Filtering calls
A__namecall hook runs for every method call in the game, which is a lot of
Luau on a hot path. Pass a filter and the work happens in C++ instead: calls that
do not match never reach your hook.
FireServer calls on a RemoteEvent:
1 is the object the method was called on. See
Filter.
Errors
Related
restoremetamethod: undo the hook.getnamecallmethod: read the method name inside a__namecallhook.checkcaller: tell your calls from the game’s.