It is a bit convoluted I agree.
There is a way to do it in yet another way, have a look at my comment and code in: Running Kotlin Scripts with bindings from a Kotlin program using ScriptEngine - #2 by bjonnh
It is a bit convoluted I agree.
There is a way to do it in yet another way, have a look at my comment and code in: Running Kotlin Scripts with bindings from a Kotlin program using ScriptEngine - #2 by bjonnh