godot.core.callable.KtCallable.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of godot-library-debug Show documentation
Show all versions of godot-library-debug Show documentation
Contains godot api as kotlin classes and jvm cpp interaction code.
package godot.core.callable
import godot.core.KtObject
import godot.core.memory.TransferContext
import godot.core.VariantType
import godot.tools.common.constants.Constraints
import godot.util.threadLocal
abstract class KtCallable(
private val name: String,
val parameterCount: Int,
val variantType: VariantType,
vararg parameterTypes: Pair
) {
private val types: Array = parameterTypes.map { it.first }.toTypedArray()
private val isNullables: Array = parameterTypes.map { it.second }.toTypedArray()
fun invoke(instance: T) {
TransferContext.readArguments(types, isNullables, paramsArray)
val ret = invokeKt(instance)
resetParamsArray()
TransferContext.writeReturnValue(ret, variantType)
}
companion object {
val paramsArray by threadLocal {
Array(Constraints.MAX_FUNCTION_ARG_COUNT) {
null
}
}
fun resetParamsArray() {
paramsArray.fill(null)
}
}
internal abstract fun invokeKt(instance: T): R
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy