Added EvalSession way of controlling all coroutines started from a script

This commit is contained in:
sergeych committed 2026-04-02 02:05:14 +03:00
1 parent 446c8d9a6e
commit fc01016a74
13 files changed
+482 -94

No files matched your search

+12 -8
View File
@@ -39,23 +39,27 @@ This brings in:
---
#### Install the module into a Lyng Scope
#### Install the module into a Lyng session
The filesystem module is not installed automatically. You must explicitly register it in the scope’s `ImportManager` using the installer. You can customize access control via `FsAccessPolicy`.
The filesystem module is not installed automatically. The preferred host runtime is `EvalSession`: create the session, get its underlying scope, install the module there, and execute scripts through the session. You can customize access control via `FsAccessPolicy`.
Kotlin (host) bootstrap example:
```kotlin
import net.sergeych.lyng.EvalSession
import net.sergeych.lyng.Scope
import net.sergeych.lyng.io.fs.createFs
import net.sergeych.lyngio.fs.security.PermitAllAccessPolicy
val scope: Scope = Scope.new()
val installed: Boolean = createFs(PermitAllAccessPolicy, scope)
// installed == true on first registration in this ImportManager, false on repeats
suspend fun bootstrapFs() {
val session = EvalSession()
val scope: Scope = session.getScope()
val installed: Boolean = createFs(PermitAllAccessPolicy, scope)
// installed == true on first registration in this ImportManager, false on repeats
// In scripts (or via scope.eval), import the module to use its symbols:
scope.eval("import lyng.io.fs")
// In scripts (or via session.eval), import the module to use its symbols:
session.eval("import lyng.io.fs")
}
```
You can install with a custom policy too (see Access policy below).
@@ -185,7 +189,7 @@ val denyWrites = object : FsAccessPolicy {
}
createFs(denyWrites, scope)
scope.eval("import lyng.io.fs")
session.eval("import lyng.io.fs")
```
Composite operations like `copy` and `move` are checked as a set of primitives (e.g., `OpenRead(src)` + `Delete(dst)` if overwriting + `CreateFile(dst)` + `OpenWrite(dst)`).