Automated updating of API pages at this location, to reflect patch changes, has ceased from 10.1.7 onwards. |
Returns a string dump of all local variables and upvalues at a given stack level.
locals = debuglocals([level])
Arguments[]
- level
- number - The stack level to inspect. Defaults to 1 (the calling function).
Returns[]
- locals
- string? - A string dump of all local variables, temporaries, and upvalues.
Details[]
- This function will return no values if called outside of the execution of the global error handler function.
Example[]
The following snippet demonstrates example output for a variety of values. Note that this snippet may not work as-is if you have an error handling addon installed, as these typically hijack and replace the ability to change the global error handler.
local Upvalue = "banana"
seterrorhandler(function()
local Number = 1.23456
local String = "foo"
local NamedFrame = { [0] = ChatFrame1[0] }
local Table = {
1,
2,
foo = "bar",
{
"debuglocals should only inspect at-most one level of tables; this shouldn't be printed",
},
}
local Thread = coroutine.create(function() end)
local Boolean = true
local Nil = nil
local Temp = Upvalue
print(debuglocals())
end)
error("")
Number = 1.234560 String = "foo" NamedFrame = ChatFrame1 { 0 = <userdata> } Table = <table> { 1 = 1 2 = 2 3 = <table> { } foo = "bar" } Thread = <no value> Boolean = true Nil = nil Temp = "banana" (*temporary) = <function> defined @Interface\FrameXML\UIParent.lua:5234 Upvalue = "banana"
Patch changes[]
Patch 10.1.0 (2023-05-02): This function will now return no results when called within a __gc
finalizer, and may now be called outside of the global error handler.
Patch 3.2.0 (2009-08-04): First usage in FrameXML appears.