setstackhidden(fnOrLevel?, hidden?) / sethiddenstack / set_stack_hidden
Hides a closure from stack inspection; hidden functions also lose their error location prefix.
Syntax
setstackhidden(fn: function | level: number, hidden: boolean?) -> ()
Parameters
| Parameter | Type | Description |
|---|---|---|
fn/level | function | number | Closure or stack level to hide. |
hidden | boolean | Defaults to true. |
Returns
| Type | Description |
|---|---|
() | No direct return values. |
Description
Hidden closures are removed from debug.info/debug.traceback results and from the GC-visible closure set.
Logic change: the executor error hook now inspects the requested level and passes level 0 to the original error when that frame is a hidden closure. error("message", 2) from a hidden caller therefore produces exactly "message" with no [string] prefix.
Example
local function hiddenCaller() error("debUNC", 2) end
setstackhidden(hiddenCaller, true)
print(select(2, pcall(hiddenCaller))) -- debUNC
Notes
- Return value behavior of debug.info and debug.traceback is unchanged.