WoW:API debugstack: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Major rewrite. Should be more easily understood now.) |
||
Line 1: | Line 1: | ||
{{wowapi}} | |||
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]]]) | |||
== Arguments == | |||
=== Parameters === | |||
a() | :;start:Number - the stack depth at which to start the stack trace (default 1 - the function calling debugstack) | ||
b() | :;count1:Number - the number of functions to output at the top of the stack (default 12) | ||
c() | :;count2:Number - the number of functions to output at the bottom of the stack (default 10) | ||
d() | |||
e() | === Returns === | ||
:;description:String - a multi-line string showing what the current call stack looks like | |||
( | If there are more than count1+count2 calls in the stack, they are separated by a "..." line. | ||
== Example == | |||
Assume the following example file, "file.lua": | |||
1: function a() | |||
2: error("Boom!"); | |||
3: end | |||
4: | |||
5: function b() a(); end | |||
6: | |||
7: function c() b(); end | |||
8: | |||
9: function d() c(); end | |||
10: | |||
11: function e() d(); end | |||
12: | |||
13: function f() e(); end | |||
14: | |||
15: function errhandler(msg); end | |||
16: print msg .. "\nCall stack: \n" .. debugstack(2, 3, 2); | |||
17: end | |||
18: | |||
19: xpcall(f, errhandler); | |||
This would output something along the following: | |||
file.lua:2: Boom! | |||
Call stack: | |||
file.lua:2: in function a | |||
file.lua:5: in function b | |||
file.lua:7: in function c | |||
... | |||
file.lua:13: in function f | |||
file.lua:19 | |||
Note that despite its all-lowercase name, this is not a core [[Lua]] function. It is a WoW API. |
Revision as of 12:25, 18 July 2006
← WoW API < debugstack
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]]])
Arguments
Parameters
- 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)
- count2
- Number - the number of functions to output at the bottom of the stack (default 10)
Returns
- description
- String - a multi-line string showing what the current call stack looks like
If there are more than count1+count2 calls in the stack, they are separated by a "..." line.
Example
Assume the following example file, "file.lua":
1: function a() 2: error("Boom!"); 3: end 4: 5: function b() a(); end 6: 7: function c() b(); end 8: 9: function d() c(); end 10: 11: function e() d(); end 12: 13: function f() e(); end 14: 15: function errhandler(msg); end 16: print msg .. "\nCall stack: \n" .. debugstack(2, 3, 2); 17: end 18: 19: xpcall(f, errhandler);
This would output something along the following:
file.lua:2: Boom! Call stack: file.lua:2: in function a file.lua:5: in function b file.lua:7: in function c ... file.lua:13: in function f file.lua:19
Note that despite its all-lowercase name, this is not a core Lua function. It is a WoW API.