Manual Stack Dump using the Stack() Function

Syntax:

stack threadID:<int> showLocals:<boolean> firstFrameOnly:<boolean> excludeOwner:<boolean> to:<stream> asString:<boolean>

This function dumps the call stack showing the nesting of function calls at the current execution point.

If threadID: is not specified, the current thread is dumped. If a thread ID is supplied, the specified thread is dumped. See the threads() method.

If showLocals: is not specified or supplied as true, the local variables in each stack frame are dumped.

If firstFrameOnly: is not specified or supplied as false, all stack frames are displayed. If supplied as true, only the current stack frame is displayed.

If to: is not specified, output is sent to the MAXScript Listener, otherwise to the supplied stream.

Available in 3ds Max 2017 and higher: If excludeOwner: is true, the dumping of the owner (if any) is not performed at each stack level. If excludeOwner: if false, a dump of the owner of the frame is included. "Owners" include rollouts, scripted plugins, and structure instances. See the second example below.

If asString: is true, the method does not write to a stream (either the listener or the stream specified by to), rather the stack capture is returned from the function as a string.

FOR EXAMPLE:

   fn test somevalue = (ss=stringstream"";stack to:ss;ss)
   fn test2 = (xx = pi; test xx)

OUTPUT:

   test()
   test2()
   StringStream:"** thread data: threadID:1184
   ** ------------------------------------------------------
   ** [stack level: 0]
   ** In test(); filename: ; position: 52; line: 1
   --  Parameters:
   --   somevalue: 3.14159
   --  Locals:
   --   somevalue: 3.14159
   --   ss: StringStream:""
   --  Externals:
   --   owner: undefined
   ** ------------------------------------------------------
   ** [stack level: 1]
   ** called from test2(); filename: ; position: 88; line: 2
   --  Locals:
   --   xx: 3.14159
   --  Externals:
   --   owner: undefined
   --   test: Global:test : test()
   ** ------------------------------------------------------
   ** [stack level: 2]
   ** called from top-level
   "

EXCLUDEOWNER EXAMPLE:

   rollout test "test"
   (
       button b "Press Me"
       on b pressed do
       (
           print "stack with owner"
           stack  excludeOwner:false
           print "\n\nstack w/o owner"
           stack excludeOwner:true
       )
   )
   createDialog test

OUTPUT:

   "stack with owner"
   **    thread data: threadID:7228
   **    ------------------------------------------------------
   **    [stack level: 0]
   **    In b.pressed(); filename: ; position: 125; line: 7
   **    member of: Rollout:test
   --     Locals:
   --     Externals:
   --         test: Rollout:test
   --         owner: Rollout:test
   --     Owner:
   --         Locals:
   --             b: RolloutControl:b in rollout:test : ButtonControl:b
   --         Externals:
   **    ------------------------------------------------------
   **    [stack level: 1]
   **    called from top-level
   "

   stack w/o owner"
   **    thread data: threadID:7228
   **    ------------------------------------------------------
   **    [stack level: 0]
   **    In b.pressed(); filename: ; position: 183; line: 9
   **    member of: Rollout:test
   --     Locals:
   --     Externals:
   --         test: Rollout:test
   --         owner: Rollout:test
   **    ------------------------------------------------------
   **    [stack level: 1]
   **    called from top-level