oth.get_original_thread

Returns the original thread associated with the hook, or nil if not in a hook thread.

Syntax

oth.get_original_thread() -> thread?

Returns

TypeDescription
thread?The original thread, or nil if not in a hook thread

Description

oth.get_original_thread returns the thread that originally called the hooked C closure. Outside an OTH hook callback it returns nil.

Example

local originalAbs
originalAbs = oth.hook(math.abs, function(value)
    local originalThread = oth.get_original_thread()
    if originalThread then
        print("Original thread:", originalThread)
    end
    return originalAbs(value)
end)

print(math.abs(-5))

Thread Context

local originalAbs
originalAbs = oth.hook(math.abs, function(value)
    local originalThread = oth.get_original_thread()

    if originalThread then
        -- We're in a hook thread
        print("Hook thread, original:", originalThread)
        -- Access thread-local data if needed
    else
        -- Not in a hook thread
        print("Not in hook thread")
    end

    return originalAbs(value)
end)

Notes

  • Returns nil if not currently executing in a hook thread
  • The returned thread is the one that originally called the hooked function
  • Useful for thread-local data access or debugging