jdemeulenaere

    jdemeulenaere

    4 years ago
    Is there a way to get the current call stack in Kotlin common code ? Something similar to currentStackTrace() on the JVM. I'd like to know the class and method name of the caller of a function. Thanks 🙂
    s

    spand

    4 years ago
    If you make it inline you can atleast get the class of the calling function
    louiscad

    louiscad

    4 years ago
    … using reified type parameters. For method name however, I don't know a multiplatform way
    jdemeulenaere

    jdemeulenaere

    4 years ago
    @spand how would you do that ?
    louiscad

    louiscad

    4 years ago
    @jdemeulenaere I just continued his message to tell how
    jdemeulenaere

    jdemeulenaere

    4 years ago
    I don't want to add parameters to my method for that. I just want a method, fun doSomething(): Unit, and in its body I want to know the name of class and function that just called the method 🙂
    louiscad

    louiscad

    4 years ago
    It's a type parameter, which can be inferred in some cases, not a regular parameter. JS reflection is limited to class names, so this is the best you can currently get on multiplatform (don't know on Kotlin/Native)
    jdemeulenaere

    jdemeulenaere

    4 years ago
    Yes, but I guess we can have access to some kind of stack trace in KotlinJS as well. I will investigate that tomorrow 🙂
    r

    robstoll

    4 years ago