Gat Tag
10/16/2024, 10:33 PMremote
package com.myexample
inline fun <R, P0> remote(crossinline func: (P0) -> R): RemoteFunction1<R, P0> {
return RemoteFunction1(TODO("Generated by compiler at call site")) { it -> func(it) }
}
data class RemoteFunction1<R, P0>(
val id: String,
val func: (P0) -> R
)
But only the calls to remote
that are in jvmMain
. Like in the example below
fun main(){
val myRemote = remote<_, Int> {
it + 3
}
}
I want to conceptually extract:
{
it + 3
}
And generate a corresponding virtual declaration in jsMain
conceptually like:
val myRemotes = mapOf<String, (Any?) -> Any?>(
"ID generated by compiler representing call site" to {
it + 3
},
// ...
)
This is a very simplistic version of what I am trying to do (I need to handle closure scopes and some other annoyances but I'm sure I'm plenty comfortable with that) I'm just not sure if or how a cross source set plugin might work.
(And if you're curious, the whole point of this is to be able to run code in the browser from a quick inline declaration on the server)Youssef Shoaib [MOD]
10/16/2024, 11:02 PMGat Tag
10/16/2024, 11:36 PMremote
as commonMain
code (i.e. it could be compiled in commonMain
and I want to throw an error at editor time if it can't). But the goal is to send an instruction to a browser (so Kotlin/JS) to run the lambda that was defined within the scope of jvmMain
Gat Tag
10/16/2024, 11:38 PMGat Tag
10/16/2024, 11:45 PMYoussef Shoaib [MOD]
10/17/2024, 12:22 AMcommonMain
? If you did that, you could simply do the transformation in IR, producing the special code in JS only.Gat Tag
10/17/2024, 1:02 AMYoussef Shoaib [MOD]
10/17/2024, 2:10 AMYoussef Shoaib [MOD]
10/17/2024, 2:11 AM