Add configurable scripting host to Olive

- Fix normalization again for reused scripting host
 - Reduce verbosity
This commit is contained in:
Edwin Jakobs
2020-02-14 14:30:50 +01:00
parent f446aab9e8
commit 2e1431ad9f
2 changed files with 28 additions and 12 deletions

View File

@@ -1,10 +1,12 @@
package org.openrndr.extra.olive
import mu.KotlinLogging
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KProperty1
import kotlin.reflect.full.declaredMemberProperties
import kotlin.reflect.jvm.jvmName
private val logger = KotlinLogging.logger {}
private val store = mutableMapOf<String, Any>()
@@ -19,11 +21,9 @@ fun clearReloadables() {
* A class with which persistent state can be reloaded from inside Olive scripts.
*/
open class Reloadable {
// -- since kotlin 1.3.61 the scripting host prepends class names with the host id
private fun normalizeClassName(name: String): String {
return name.replace(Regex("ScriptingHost[0-9a-f]+_"), "")
return name.replace(Regex("ScriptingHost[0-9a-f]+_"), // -- since kotlin 1.3.61 the scripting host prepends class names with the host id
"").replace(Regex("Line_[0-9]+"),"") // -- when reusing the script engine the line number increments.
}
/**
@@ -41,14 +41,14 @@ open class Reloadable {
val value = (e as KProperty1<Any, Any?>).get(existing)
val mp = (p as KMutableProperty1<Any, Any?>)
mp.set(this, value as Any)
println("reloaded property ${p.name} <- ${value}")
logger.info("reloaded property ${p.name} <- ${value}")
} catch (e: Throwable) {
println("error while reloading property ${p.name}: ${e.message}")
logger.warn("error while reloading property ${p.name}: ${e.message}")
}
}
}
} else {
println("no existing store found for $className")
logger.info("no existing store found for $className")
}
store[normalizeClassName(this::class.jvmName)] = this
}