oth.hook
Hooks a C closure with a Luau callback.
Syntax
oth.hook(target: function, hook: function) -> functionParameters
| Parameter | Type | Description |
|---|---|---|
target | function | The C function to hook |
hook | function | The replacement Luau closure |
Returns
| Type | Description |
|---|---|
function | A reference to the original function |
Description
oth.hook replaces calls to the target C closure with the supplied Luau callback and returns the original function.
Example
-- Hook a C function
local originalAbs
originalAbs = oth.hook(math.abs, function(value)
print("Hooked call:", value)
return originalAbs(value)
end)
print(math.abs(-5)) -- Hooked call: -5, then 5Notes
- Only works with C functions (not Luau closures)
- The hook argument must be a Luau closure, not another C closure
- Use
oth.is_hook_thread()to detect hook context - The returned original can be called to bypass the hook
- Remove hooks with
oth.unhook
Related Functions
oth.unhook- Remove a hookoth.get_root_callback- Get original functionoth.is_hook_thread- Check hook thread context