GithubHelp home page GithubHelp logo

Kotlin Scripting support about kscript HOT 3 OPEN

aartiPl avatar aartiPl commented on June 17, 2024
Kotlin Scripting support

from kscript.

Comments (3)

aartiPl avatar aartiPl commented on June 17, 2024

@ligee, @ileasile - as I have mentioned in #Kotlin/KEEP, I have an initial implementation of support for Kotlin Scripting in kscript. Those files are mostly a copy of Kotlin Scripting files - I have divided the evaluation into 2 phases: compilation and execution because I want to get compilation messages first, and then the output of the application, not everything at the end.

The problems which I have encountered:

  1. Compiler sees the incorrect path of the root file, and I don't know how to modify this path programmatically.
    Please look at KscriptHost.kt 'compile' function. I am setting the path of the file explicitly in line 57. But during compilation, the path of the root file is always resolved to the current directory.
    See the below screenshot for details:
    obraz

(As you can see, I am starting the script from home dir; internally, kscript is resolving script dir correctly, but I don't know how to pass it to the compiler, and as a result, the path is resolved incorrectly)

  1. Is it necessary to provide jar cache through system properties?

  2. How to get all compiled file names and paths (needed for creating the IntelliJ project)?

  3. How to get all dependencies (needed for creating of IntelliJ project)?

  4. How to implement URL resolving with caching files locally?

As there is lacking documentation, it is difficult to determine what's wrong with my implementation. Can you help with the above problems (the first one is very practical as I am currently on it; for others, it would be nice to get some hints, at least)?

from kscript.

aartiPl avatar aartiPl commented on June 17, 2024

I have renamed the branch to kscript_4.5 - it's too early to release Kotlin Scripting in the next version.
https://github.com/kscripting/kscript/tree/kscript_4.5

from kscript.

ligee avatar ligee commented on June 17, 2024

@aartiPl, it is great to see your efforts to implement kscript on top of the scripting API.
Let's have a look at your questions:

  1. if you're talking about scriptFileLocation - this variable is set by the compiler, and used inside the evaluator for script to be able to access its own path (e.g. by default via the __FILE__ variable).
    If you need to set the script's "virtual path" for diagnostics and maybe imports, you need to implement your own variant of the SourceCode rather than use toScriptSource function, or alternatively use FileScriptSource and pass a correct file to it along with the text.

  2. What do you mean by jar cache, and where do you provide it via the system properties?

  3. The scripts are by default do not compile into files, they are kept in memory. If you need them as class files, you need to use pseudo-evaluation into a cache. You can find an example of this functiunality around usages of this class - https://github.com/JetBrains/kotlin/blob/3e19e9d190f800da551650cdcbbdbb9f7c845f07/libraries/scripting/jvm-host-test/test/kotlin/script/experimental/jvmhost/test/CachingTest.kt#L342
    (BTW, quite likely you can use the same approach for generating the whole IntelliJ project.)

  4. All dependencies are stored in the dependencies property of the compilation configuration, and you can get the resulting configuration from the compiled script and it will include also the dependencies resolved from maven and other sources, if applicable.

  5. I guess you mean some variant of the @Import handling. In the main-kts, it is implemented here - https://github.com/JetBrains/kotlin/blob/ca2f37f6ebe9dd7349cc4cab1e1ab1ddfdb5976e/libraries/tools/kotlin-main-kts/src/org/jetbrains/kotlin/mainKts/scriptDef.kt#L176
    and you can adapt this code for your case.

from kscript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.