api

package
v1.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LetGo

type LetGo struct {
	// contains filtered or unexported fields
}

func NewLetGo

func NewLetGo(ns string, opts ...Option) (*LetGo, error)

NewLetGo constructs a runtime. With no options, behavior is exactly as it was pre-option: *out* and *err* keep their global default root bindings (os.Stdout / os.Stderr). Each I/O option installed gets pushed as a dynamic binding around each Run call, so different LetGo instances don't share or overwrite each other's I/O routing.

func (*LetGo) Def

func (l *LetGo) Def(name string, value any) error

func (*LetGo) Run

func (l *LetGo) Run(expr string) (vm.Value, error)

Run compiles and evaluates expr. If this LetGo was constructed with WithStdout / WithStderr, the corresponding IOHandle is pushed as a dynamic binding on *out* / *err* for the eval's scope and popped on return (including on error / panic).

Two LetGo instances calling Run sequentially each get their own configured streams: A's Run pushes A's handle, evaluates, pops; then B's Run pushes B's handle. The root binding of *out*/*err* is never mutated.

func (*LetGo) SetLoadPath

func (l *LetGo) SetLoadPath(path []string)

type Option added in v1.11.0

type Option func(*config)

Option configures a LetGo runtime instance at construction. Options are applied in order; later options override earlier ones for the same configuration key.

func WithEmit added in v1.11.0

func WithEmit(fn func(name, dataJSON string)) Option

WithEmit configures the runtime to route (js/emit event-name data) through fn for this instance, the emit dual of WithStdout. fn receives the event name and the JSON-marshaled data — the same (name, dataJSON) pair the WASM bundle hands to LetGoHost.onEmit — so a Go embedder gets the events its guest dispatches without depending on the browser host.

Implementation: each Run pushes a FuncEmitter wrapping fn as a dynamic binding on *emit*, popped on return. Same per-Run isolation and process-global-binding-stack concurrency caveat as WithStdout.

Default: no-op (the *emit* root nopEmitter; (js/emit ...) is dropped).

func WithKeySource added in v1.11.0

func WithKeySource(ks rt.KeySource) Option

WithKeySource routes term/read-key and key-pending? through ks for this instance, the input dual of WithStdout. An embedder or test supplies the keystrokes the guest reads — driving a TUI without a real terminal, or feeding a deterministic script. ks is an rt.KeySource (ReadKey + KeyPending); see pkg/rt/keysource.go.

Implementation: each Run pushes ks as a dynamic binding on *keys*, popped on return. Same per-Run isolation and process-global-binding-stack concurrency caveat as WithStdout.

Default: the platform key source (stdin+SIGWINCH on native, the SAB in WASM). Wake — unblocking a parked read-key without a real key — is not part of this seam yet; see the note in pkg/rt/wasm/lg-host.js.

func WithStderr added in v1.11.0

func WithStderr(w io.Writer) Option

WithStderr configures the runtime to route output written via *err* (HTTP server error logs, pod stderr, panic reports, etc.) through w for this runtime instance. Same per-Run binding semantics as WithStdout; same concurrency caveat.

Default: os.Stderr.

func WithStdout added in v1.11.0

func WithStdout(w io.Writer) Option

WithStdout configures the runtime to route output written via *out* (i.e. (println ...), (print ...), (pr ...), (prn ...), and any user code that consults *out*) through w for this runtime instance.

Implementation: each Run call pushes an IOHandle wrapping w as a dynamic binding on *out*, then pops it on return. Per-Run scope means two LetGo instances with different WithStdout values DO NOT interfere with each other's sequential output capture, and a LetGo constructed without WithStdout sees the unaltered os.Stdout default regardless of what other instances have done.

Concurrency caveat: vm.Var's binding stack is process-global. If two goroutines call Run on different LetGo instances concurrently, their bindings push onto the same *out* stack — push/pop interleavings can scramble captures. For deterministic isolation, serialize Run calls or run different instances in different processes.

Default: os.Stdout (no binding pushed; runtime root unchanged).

func WithStorage added in v1.11.0

func WithStorage(store rt.Storage) Option

WithStorage routes the storage namespace through store for this instance. The store receives app-local logical keys; callers should not encode host filesystem or browser-origin details into those keys.

Implementation: each Run pushes store as a dynamic binding on *storage*, popped on return. Same process-global-binding-stack concurrency caveat as WithStdout.

Default: the runtime root binding. In ordinary native lg this is a file-backed store configured by the CLI; in bare embedders it is in-memory.

Error contract: a store must distinguish an absent key (storage/get yields nil) from a backend failure (throws in the guest) — see rt.Storage.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL