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
| Type | Description |
|---|---|
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
nilif 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
Related Functions
oth.hook- Create a hookoth.is_hook_thread- Check if in a hook thread