Hey! i'm currently working on a server, where i ne...
# scripting
l
Hey! i'm currently working on a server, where i need to be able to configure rather complicated actions. I've currently built a proof of concept DSL for that, and it's great. But i need to be able to reconfigure it without having to restart / recompile my server, so just putting the DSL into the server is no option. I thought about using Kotlin-script for that purpose. I'd need to somehow expose my DSL api to kotlin-script, evaluate that script from my Kotlin-server and get the configuration back. is this currently possible, or say practical with Kotlinscript? there are two questions: - how can i get my type-safe DSL API into kotlinscript? - how could i get the generated objects back from the script? any help would be appreciated ;D
n
the type safe dsl can just be available by being compiled in and importing it in the script (IDE integration might pick that up too) the implicit return.. eg. last statement can be gotten back and checked if it is something or Unit, than you can typecheck and cast it what you want to do is certainly possible.. and i would suggest to set it up in a way that monitors a .config.kts file and re-evaluates on change .. so you just need to upload to apply the config
l
how would i get it back? is there some way to execute the kotlinscript from the running kotlin server and retrieve an object from it? i thought my only option would be to execute it like shell-scripts and such via Runtime.exec or something and then maybe get the result back as JSON or somethingg....
j
Your script is evaluated on an instance of your class annotated with @KotlinScript, and you can retrieve that object after evaluating the script
This is how I do it; not sure this is the best way though: https://pastebin.com/UJ78p8q6
👍 1
l
So the variables declared in the Script get converted into an inszance of your config script class by using
as
? Thats cool, gonna try that 😉 i also read into the java jsr-223 API yesterday, ill need to try that too