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_threadreturnstrue.oth.get_original_threadreturns 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 ongame.__namecallsees 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): functionParameters
| Parameter | Type | Description |
|---|---|---|
target | function | C function to hook. |
replacement | function | Lua 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.
