How to detect caller in haxe?
Asked Answered
K

1

5

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?

Khartoum answered 7/12, 2013 at 17:5 Comment(0)
A
9

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
Aboulia answered 8/12, 2013 at 2:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.