AcediaDocumentation

oth.hook

Installs an off-thread hook for a C function.

Replaces target with a stand-in that runs replacement on a fresh coroutine each time the target would be called, and returns a callable clone of the original. The replacement must be Lua code.

Each invocation creates a new coroutine via coroutine.create(replacement) and dispatches it with coroutine.resume, so the body runs on a thread distinct from the caller's. Inside the body:

  • coroutine.running() returns the fresh carrier, not the caller.
  • oth.is_hook_thread returns true.
  • oth.get_original_thread returns the thread the target was called from.
  • getnamecallmethod() returns the method that was in flight on the caller when the target was reached, so a hook on game.__namecall sees the original method name.

The returned original can be called from inside the body to forward to the real target. Because the body runs on a proper coroutine, that call behaves exactly as a direct invocation would and preserves all return values, including those of __namecall dispatch to yielding methods.

oth.hook(target: function, replacement: function): function

Parameters

ParameterTypeDescription
targetfunctionC function to hook.
replacementfunctionLua callback executed on the carrier coroutine.

Errors: Rejects a Lua target or a C replacement. Fails when coroutine.create or coroutine.resume is not reachable from the globals table.

On this page