OTH

Layered native-function replacements and their calling-thread context.

6 functionssUNC 100%Lynx 0.0.0

The oth table manages layered native-function replacements with a logical calling-thread context. It is separate from the standard closure APIs.

oth.hook

oth.hook(target: function, replacement: function, inlineOrFilter: boolean | FilterBase?): function

Adds a replacement layer to a C target and returns the previous-call relay. The replacement must be a Lua function. The third argument is either the legacy inline boolean or a FilterBase; a filter does not implicitly enable inline mode. Invalid targets and incompatible existing modifications raise an argument error.

oth.unhook

oth.unhook(target: function, selector: function?): boolean

Removes the selected replacement/relay layer, or all enabled layers when selector is omitted. Returns whether any layer was removed. Active calls retain the resources they need until completion.

oth.get_root_callback

oth.get_root_callback(): function?

Returns the root previous-call callback for the current active replacement invocation, or nil outside that context.

oth.is_hook_thread

oth.is_hook_thread(): boolean

Returns whether the current thread belongs to a managed replacement invocation.

oth.get_original_thread

oth.get_original_thread(): thread?

Returns the original calling thread for the current managed invocation, or nil outside that context.

oth._ydiag

oth._ydiag(): (number, number, number, number, number, number)

Returns six internal diagnostic counters in source order: collapse, protected-call, namecall, continuation-present, direct-call and cloned-continuation counts. This diagnostic is currently registered on the oth table.

local previous
previous = oth.hook(math.abs, function(x)
return previous(x)
end)
local ok, value = pcall(math.abs, -7)
oth.unhook(math.abs, previous)
print(ok, value)