Kotlin / dukat

Converter of <any kind of declarations> to Kotlin external declarations
557 stars 42 forks source link

Delegation could be used to support string literal names #394

Open KotlinIsland opened 4 years ago

KotlinIsland commented 4 years ago
export interface Bar {
    "asdf.asdf": string;
}

Could be represented by:

import kotlin.reflect.KProperty

external interface Bar

var Bar.asdf_asdf: String by UsingGet("asdf.asdf")

class UsingGet<T>(val name: String) {
    inline operator fun getValue(thisRef: Any, property: KProperty<*>): T {
        return thisRef.asDynamic()[name]
    }
    inline operator fun setValue(thisRef: Any, property: KProperty<*>, value: T) {
        thisRef.asDynamic()[name] = value
    }
}