
godot.core.callable.KtCallable.kt Maven / Gradle / Ivy
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 - 2025 Weber Informatics LLC | Privacy Policy