18 · Modules
Kotlin with extern
Kotlin functions, suspend APIs, live objects and Maven libraries.
On this page
Import kotlin from the same jvm plugin that provides Java. The signature
uses Zolo types and the body uses Kotlin. Call the result like any other Zolo
function. These programs run with the CLI and an installed JVM plugin.
Use Kotlin templates, exact Long values, a captured expression, a callback and async.
// parity-timeout-ms:300000
use plugin jvm::{kotlin}
extern kotlin fn greet(name: str) -> str {
return "Olá, $name!"
}
extern kotlin fn exact(value: int) -> int {
return value
}
extern kotlin fn relay(callback: fn(int) -> int) -> int {
return callback(41L)
}
extern kotlin async fn later(value: int) -> int {
import kotlin.coroutines.suspendCoroutine
import kotlin.coroutines.resume
return suspendCoroutine { continuation ->
Thread { continuation.resume(value + 1L) }.start()
}
}
let value = 40
let answer: int = extern kotlin { value + 2L }
print(greet("Kotlin"))
print(exact(9007199254740993))
print(relay(|number| number + 1))
print(answer)
print(await later(41))
// expected:
// Olá, Kotlin!
// 9007199254740993
// 42
// 42
// 42
Requires the Zolo CLI/host — open in the playground or run locally.
int maps to Kotlin Long; use i32 for Kotlin Int.
str maps to String, nullable values to nullable native types, arrays to
typed collections and callbacks to Kotlin function types.
For a standalone capture, specify the expected result:
let answer: int = extern kotlin { value + 2L }.
Sources and objects
Import a Kotlin class, construct it with .new and update its mutable property.
use plugin jvm::{kotlin as k}
extern k from "./kotlin_fixtures/Person.kt" use {Person}
extern k fn same(person: Person) -> Person {
return person
}
let person = Person.new(name: "João", age: 30)
print(person.name)
person.age = 31
print(person.age)
print(person.greeting())
print(person == same(person))
// expected:
// João
// 31
// Olá, João!
// true
Requires the Zolo CLI/host — open in the playground or run locally.
extern kotlin from "./Person.kt" use {Person} follows the importing Zolo
file. Supported public classes expose constructors, methods and mutable
properties. Live objects retain their native identity and state across prepared
bindings. Reachable sibling Kotlin sources are compiled together.
extern kotlin async fn creates a real suspend function and returns a Zolo
Future. Imported suspend APIs and Java CompletionStage results use the same
async boundary. Kotlin callbacks return to the owning Zolo runtime and may make
nested foreign calls. Cancellation requests interruption or cancellation of the
adapted operation; work that ignores it can continue.
Maven and setup
Use Guava with a single global Maven dependency declaration.
// Prepare with `zolo install` or `zolo run ... --install=auto`.
use plugin jvm::{kotlin}
extern kotlin deps {
"com.google.guava:guava" = "33.4.0-jre"
}
extern kotlin fn join(values: [str]) -> str {
import com.google.common.base.Joiner
return Joiner.on(", ").join(values.asIterable())
}
print(join(["Kotlin", "Maven", "Zolo"]))
// expected:
// Kotlin, Maven, Zolo
Requires the Zolo CLI/host — open in the playground or run locally.
Kotlin and Java share extern ... deps and
[foreign.jvm.dependencies] declarations. Prepare with
zolo install main.zolo, or permit first-run preparation with
--install=auto. Projects default to manual installation.
--offline --frozen consumes the prepared, locked closure.
Source preparation and native editor queries need a Java8+ JDK and the pinned Kotlin compiler/tooling closure. From a repository checkout, acquire it explicitly:
python plugins/jvm/tools/install-kotlin.py --destination .zolo-tools/kotlin-2.3.20
Set the printed ZOLO_KOTLIN_HOME and ZOLO_KOTLIN_ANALYSIS_HOME paths;
ZOLO_JAVA_HOME selects Java. Acquisition verifies pinned SHA256 hashes and
does not change a global Kotlin installation. Opening the editor does not
download dependencies or execute authored code.
Compiler and analysis helpers produce diagnostics/bytecode in isolated temporary workspaces; invocation runs through JNI inside the Zolo process. Editor features use Kotlin's native Analysis API over current unsaved text, including supported autoimport edits.
Artifacts retain compiled classes, Kotlin stdlib, dependencies and source snapshots. VM, native and LLVM support dynamic/embed/static plugin packaging without original sources or the Kotlin compiler. Deployment still needs a compatible JRE. The default target is Java8; newer APIs and libraries may require a newer runtime. Hosted wasm-aot execution is unavailable. Acceptance currently covers Windows x64; other platforms need independent validation.
See also