ReferenceClosures

oth.hook

Installs a hook whose body runs in a separate task while the caller waits for its results.

Syntax

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

Parameters

ParameterTypeDescription
targetfunctionFunction to replace.
hookfunctionCallback executed in the separate task.

Returns

TypeDescription
functionOriginal callable returned by the hook installation.

Description

The callback receives the target’s arguments. Returned values and errors are delivered to the waiting caller. The supported wait is bounded; a hook must not leave its caller waiting indefinitely. Use oth.unhook to restore the target. This is separate from an ordinary hookfunction call.

Example

local function target(x) return x + 1 end
local original = oth.hook(target, function(x) return x * 2 end)
print(target(3))
oth.unhook(target)

Notes

These are Game executor contracts. Check build requirements and session lifetimes before using them.