openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.58k forks source link

Add Kotlin scripting support #9372

Open chris922 opened 3 years ago

chris922 commented 3 years ago

I saw that openHAB supports JSR223 and within the PR #8772 it looks like it's quite easy to add new languages.

Because I personally prefer Kotlin over Groovy I thought it maybe can added as a scripting engine as well.

I am personally not deep into JSR223 stuff and openHAB development, but I already had a look if Kotlin provides a JSR223 compatible script factory and indeed it does: KotlinJsr223JvmLocalScriptEngineFactory.

Maybe helpful resources:

If you prefer I could try with a PR similar to #8772, but I really don't know if some prework was done and also how to easily setup a test-environment so that I can verify kotlin-script is working. If you can provide me some resources how to start I would give it a try as long as you don't have time left for this.

wborn commented 3 years ago

I had a brief look at this already but it was not as easy as the Groovy add-on. :wink: I read that the Kotlin performance was really bad compared to other JSR223 languages. The Kotlin artifacts are also not OSGi friendly with shared packages and a lot of dependencies.

chris922 commented 3 years ago

Ah.. Pity! Thanks for the response, maybe someone can create a ticket on Kotlin side so that they maybe improve their JSR223 support?

Legion2 commented 3 years ago

The Kotlin artifacts are also not OSGi friendly with shared packages and a lot of dependencies.

@wborn Which kotlin artifacts would be required for the scripting support?

wborn commented 3 years ago

I got rid of the code after my experiments and no longer remember all the details. 🤔

cable729 commented 11 months ago

https://github.com/Kotlin/kotlin-script-examples/blob/master/jvm/jsr223/jsr223.md may have some pointers