Added thread parameter and example.
(Added a second example that can pull the line number of itself in a file. Useful for debug purposes in an addon.) |
(Added thread parameter and example.) |
||
| Line 3: | Line 3: | ||
Output a string representation of the current calling stack, similar to the standard Lua debug.traceback() call, which is not present in WoW. | Output a string representation of the current calling stack, similar to the standard Lua debug.traceback() call, which is not present in WoW. | ||
description = debugstack([start[, count1[, count2]]]) | description = debugstack([thread, ][start[, count1[, count2]]]]) | ||
== Arguments == | == Arguments == | ||
=== Parameters === | === Parameters === | ||
:;start:Number - the stack depth at which to start the stack trace (default 1 - the function calling debugstack) | :;thread:Thread - a coroutine thread, obtained with coroutine.create(). Use to inspect the current call stack inside a coroutine that has yielded or died. | ||
:;start | |||
:Number - the stack depth at which to start the stack trace (default 1 - the function calling debugstack) | |||
:;count1:Number - the number of functions to output at the top of the stack (default 12) | :;count1:Number - the number of functions to output at the top of the stack (default 12) | ||
:;count2:Number - the number of functions to output at the bottom of the stack (default 10) | :;count2:Number - the number of functions to output at the bottom of the stack (default 10) | ||
| Line 64: | Line 66: | ||
This would return the following output from print: | This would return the following output from print: | ||
Debug Print on Line 7 with message: We tried to do something. | Debug Print on Line 7 with message: We tried to do something. | ||
== Example 3 == | |||
Using debugstack to find out the location of an error in a coroutine. | |||
1: function f() | |||
2: print ("a">0) -- this will cause an error | |||
3: end | |||
4: | |||
5: thread = coroutine.create(f) | |||
6: executed_ok,message = coroutine.resume(thread) | |||
7: | |||
8: if not executed_ok then | |||
9: print("Error: "..message.." in "..debugstack(thread)) | |||
10: end | |||
Note that despite its all-lowercase name, this is not a core [[Lua]] function. It is a WoW API. | Note that despite its all-lowercase name, this is not a core [[Lua]] function. It is a WoW API. | ||