Skip to main content

Module host

Module host 

Source
Expand description

Ready-made BopHost building blocks for embedders.

Most embedders only need two things beyond the default trait impl: a way to plug in a module resolver, and a way to capture print output. This module provides both as composable pieces so you can mix-and-match without re-implementing the whole trait from scratch.

use bop::host::{StringModuleHost, resolve_from_map};
use bop::BopLimits;

// Map of module-name → source, resolved in-process (no I/O).
let mut host = StringModuleHost::new([
    ("greetings", "fn hello() { print(\"hi\") }"),
]);
bop::run("use greetings\nhello()", &mut host, &BopLimits::standard())
    .unwrap();

The helpers intentionally stay minimal — they don’t own the terminal, they don’t touch the filesystem, they don’t parse environment variables. Embedders that want richer behaviour should implement BopHost directly or wrap these helpers.

Structs§

StringModuleHost
A minimal BopHost that captures print output and serves modules from an in-memory string table.

Functions§

resolve_from_map
Build a BopHost::resolve_module implementation from an in-memory table of (module_path, source) pairs.