kscripting / kscript

Scripting enhancements for Kotlin
MIT License
2.07k stars 126 forks source link

Can kscript used in Android project written in kotlin #411

Open wisdomtl opened 1 year ago

wisdomtl commented 1 year ago

I want to do this:

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        kscript.eval("val x =3")
        val result = kscript.eval("x+2")
        Log.d("test", "onCreate: result=$result")
    }
}

can kscript achieve this?

thanks for reading my stupid question.

aartiPl commented 1 year ago

Well, they are saying that there are no stupid questions. And I kind of agree with that :-D

In the case of kscript, you can do something similar by calling KscriptHandler.handle() function. Please see at Kscript.kt and KscriptHandler.kt files. But please remember that currently, you need to have Kotlin compiler installed in the system, which is called internally by kscript. From that point of view, I think kscript is unsuitable for your use case.