Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect caller in haxe?

Tags:

haxe

I am setting a property, I need to know who is setting the property value? is this possible in haxe 3?

Also, can I know who is calling a function from inside the function itself?

like image 700
simo Avatar asked Dec 07 '13 17:12

simo


Video Answer


1 Answers

Check out PosInfos. You use it like so:

public static function add(a:Int, b:Int, ?pos:PosInfos) {
    trace( 'Called from ${pos.className}');
    trace( 'Called from ${pos.methodName}');
    trace( 'Called from ${pos.fileName}');
    trace( 'Called from ${pos.lineNumber}');
    return a+b;
}

add( 1, 1 ); // "pos" will automatically be filled in by compiler
like image 168
Jason O'Neil Avatar answered Sep 22 '22 02:09

Jason O'Neil