All Downloads are FREE. Search and download functionalities are using the official Maven repository.

godot.core.callable.KtCallable.kt Maven / Gradle / Ivy

There is a newer version: 0.11.0-4.3
Show newest version
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