eddsteel / starlark

Starlark as a standalone java library.

Home Page:https://github.com/bazelbuild/starlark

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Starlark

This provides Starlark as a standalone java library, distinct from Bazel. There is no API stability guarantee, so do exercise caution if you decide to use this library.

Installation

This library is published to Github Packages, you can add it in your project fairly easily.

Using Gradle

repositories {
    maven {
        url = uri("https://maven.pkg.github.com/cyberdelia/starlark")
        credentials {
            username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_USERNAME")
            password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN")
        }
    }
}

dependencies {
    implementation("com.lapanthere:starlark:4.2.1")
}

You can also refer to Github documentation for further details.

Using Maven

<dependencies>
    <dependency>
        <groupId>com.lapanthere</groupId>
        <artifactId>starlark</artifactId>
        <version>4.2.1</version>
    </dependency>
</dependencies>

You can also refer to Github documentation for further details.

Usage

To embed and use the interpreter in your program:

Java

StarlarkSemantics semantics = StarlarkSemantics.DEFAULT;
try (Mutability mu = Mutability.create("scope")) {
    StarlarkThread thread = new StarlarkThread(mu, semantics);
    Module module = Module.withPredeclared(semantics, new HashMap<>());
    Program program = Program.compileExpr(Expression.parse(ParserInput.fromLines("print('hello)")), module, FileOptions.DEFAULT);
    Starlark.execFileProgram(program, module, thread);
}

Kotlin

Mutability.create("scope").use { mu ->
    val semantics = StarlarkSemantics.DEFAULT
    val thread = StarlarkThread(mu, semantics)
    val module = Module.withPredeclared(semantics, emptyMap())
    val program =
        Program.compileExpr(Expression.parse(ParserInput.fromLines("""print("hello)""")), module, FileOptions.DEFAULT)
    Starlark.execFileProgram(program, module, thread)
}

About

Starlark as a standalone java library.

https://github.com/bazelbuild/starlark


Languages

Language:Starlark 100.0%