oth.hook

Hooks a C closure with a Luau callback.

Syntax

oth.hook(target: function, hook: function) -> function

Parameters

ParameterTypeDescription
targetfunctionThe C function to hook
hookfunctionThe replacement Luau closure

Returns

TypeDescription
functionA 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 5

Notes

  • 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