Add support for passing custom parameters to script
This commit is contained in:
@@ -4,7 +4,7 @@ import io.smnp.data.entity.Note
|
||||
import io.smnp.type.model.Value
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
enum class DataType(val kotlinType: KClass<out Any>, val stringifier: (Any) -> String) {
|
||||
enum class DataType(private val kotlinType: KClass<out Any>, val stringifier: (Any) -> String) {
|
||||
INT(Int::class, { it.toString() }),
|
||||
FLOAT(Float::class, { it.toString() }),
|
||||
STRING(String::class, { it.toString() }),
|
||||
|
||||
@@ -41,6 +41,20 @@ data class Value(val type: DataType, val value: Any, val properties: Map<String,
|
||||
return Value(DataType.INT, value)
|
||||
}
|
||||
|
||||
fun wrap(obj: Any): Value {
|
||||
return when(obj) {
|
||||
is Unit -> void()
|
||||
is Int -> int(obj)
|
||||
is Float -> float(obj)
|
||||
is Boolean -> bool(obj)
|
||||
is String -> string(obj)
|
||||
is Note -> note(obj)
|
||||
is List<*> -> list((obj as List<Any>).map { wrap(it) })
|
||||
is Map<*, *> -> map((obj as Map<Any, Any>).map { (k, v) -> wrap(k) to wrap(v) }.toMap())
|
||||
else -> throw ShouldNeverReachThisLineException()
|
||||
}
|
||||
}
|
||||
|
||||
fun float(value: Float): Value {
|
||||
return Value(
|
||||
DataType.FLOAT,
|
||||
|
||||
Reference in New Issue
Block a user