Is there a way to get the current call stack in Ko...
# multiplatform
j
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
If you make it inline you can atleast get the class of the calling function
l
… using reified type parameters. For method name however, I don't know a multiplatform way
j
@spand how would you do that ?
l
@jdemeulenaere I just continued his message to tell how ☝️
j
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 🙂
l
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)
j
Yes, but I guess we can have access to some kind of stack trace in KotlinJS as well. I will investigate that tomorrow 🙂
r
163 Views