https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

jdemeulenaere

06/27/2018, 12:34 PM
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

06/27/2018, 2:18 PM
If you make it inline you can atleast get the class of the calling function
l

louiscad

06/27/2018, 5:30 PM
… using reified type parameters. For method name however, I don't know a multiplatform way
j

jdemeulenaere

06/27/2018, 9:03 PM
@spand how would you do that ?
l

louiscad

06/27/2018, 10:35 PM
@jdemeulenaere I just continued his message to tell how ☝️
j

jdemeulenaere

06/27/2018, 10:37 PM
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

louiscad

06/27/2018, 10:40 PM
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

jdemeulenaere

06/27/2018, 10:53 PM
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

06/28/2018, 5:35 AM
33 Views