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.
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:
Errors
Related
restoremetamethod: undo the hook.getnamecallmethod: read the method name inside a__namecallhook.checkcaller: tell your calls from the game’s.