Prev | Current Page 374 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"


The signature for the callStack() function is:
haxe.Stack.callStack() : Array < haxe.StackItem > ;
As you can see, when called, an array listing the call stack details using the haxe.StackItem
enumerator is returned. The haxe.StackItem enum, at least in this case, will return the class and
method names of the call. However, if you would rather just dump the contents of each StackItem , you
can do so using the haxe.Stack.toString() method.
Let ??™ s see this in an example:
class CallStack
{
public static function main()
{
var i : Int = 0;
i = add( i, 6 );
}
public static function add( a, b )
{
return a + minus( b, 2 );
}
public static function minus( a, b )
{
return a - multiply( b, 2 );
}
public static function multiply( a, b )
{
return a * traceStack( b );
}
public static function traceStack( a )
193
Chapter 7: When Things Go Wrong
{
var cs = haxe.Stack.callStack();
trace( haxe.Stack.toString( cs ) );
return a;
}
}
If you compile this class and run it, you should be presented with the following output:
CallStack.


Pages:
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386