Hello Community,
At the moment, I have two functions, which are able to add and evaluate a lambda from a MutableList.
Now, I want to save this List to a file in a human-readable format and later load them again and evaluate the lambdas.
What is the best approach? Can I use JSON to save them? And edit them externaly.
I want to avoid the ScriptEngine because I'm using linux aarch as host so kotlin/native did not work nor is the jna library compatible.
Here is my code so far:
Copy code
typealias func = ()-> Unit
@JvmField val command = mutableListOf<func>()
fun main() {
add {
val i =4
println("${i}")
}
eval(command[0])
}
fun add(action: () -> Unit): Unit {
command.add(action)
}
fun eval(action: () -> Unit) {
action()
}
Thank you
j
Joffrey
09/13/2021, 1:01 PM
You can't really serialize code as JSON, so yeah I would suggest using the script engine. Script engine doesn't mean you have to run on Native, though. You can run it in the JVM.
👍 1
p
PriNova
09/13/2021, 1:05 PM
@Joffrey Thank you for your quick reply. I will give the ScriptEngine a try.