typedef haxe.PosInfosAvailable in flash8, flash, neko, js, php, cpp, cs, java
var methodName : String var lineNumber : Int var fileName : String var customParams : Array<Dynamic> var className : String
version #17793, modified 2013-02-27 23:29:51 by api
1 comment
  • Dec 06, 2012 at 05:19

    PosInfos is most useful when it is set automatically by the Haxe compiler. Basically, if you have a method with an optional parameter of type "PosInfos", when you call that method, and you don't give a value, the Haxe compiler will automatically insert one for you. For example:

        static function areEqual(a:Dynamic, b:Dynamic, ?p:haxe.PosInfos)
            if (a != b)
                trace (Std.string(a) + " was not equal to " + Std.string(b));
                trace ("  at " + p.fileName + ":" + p.lineNumber + " in method " + p.methodName);

    If you now called that method:

        areEqual(7, 8);

    the value for "p" would automatically be inserted and include all the information about the line that called the method - the file it was in, the line number, the method etc.

    There are two common uses for this. The first is for trace functions (see http://haxe.org/doc/cross/trace) or assert functions (as in the example above), when you are debugging and the function should tell you something about where the code was called from.

    The second common use is if the function's behaviour changes depending on where it was called from. For example, if you had a function "includeTemplate()", which included a different template depending on which class or method called it.