Kotlin / dukat

Converter of <any kind of declarations> to Kotlin external declarations
554 stars 44 forks source link

Generate builder functions for SAM like interfaces #191

Open bashor opened 7 years ago

bashor commented 7 years ago

Examples:

external interface MyFunction {
    @nativeInvoke
    fun invoke(a: Int, b: String): Int
}

inline fun MyFunction(f: (a: Int, b: String) -> Int): MyFunction {
    return f.unsafeCast<MyFunction>()
}

external interface MyFunctionWithVararg {
    @nativeInvoke
    fun invoke(a: Int, vararg b: String): Int
}

inline fun MyFunction(f: (a: Int, b: String) -> Int): MyFunctionWithVararg {
    return { a -> f(a, js("arguments").slice(1)) }
}
Schahen commented 4 years ago

Covered in a proposal we have in "DUKAT-9. Light-weight builder for (presumably) config-like interfaces".

Ayfri commented 3 years ago

Any update ?