package dev.isxander.yacl3.dsl import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty class RegisterableDelegateProvider( private val registerFunction: (id: String) -> R, private val id: String?, ) { operator fun provideDelegate(thisRef: Any?, property: KProperty<*>): ExistingDelegateProvider { return ExistingDelegateProvider(registerFunction(id ?: property.name)) } } class RegisterableActionDelegateProvider( private val registerFunction: (String, Dsl.() -> Unit) -> Return, private val action: Dsl.() -> Unit, private val name: String? ) { operator fun provideDelegate(thisRef: Any?, property: KProperty<*>): ExistingDelegateProvider { return ExistingDelegateProvider(registerFunction(name ?: property.name, action)) } } class ExistingDelegateProvider( private val delegate: Return ) : ReadOnlyProperty { override fun getValue(thisRef: Any?, property: KProperty<*>): Return { return delegate } }