Plugins
A program can load Brass code built separately, as a shared library:
because in the shared packagepub trait Tool { fn run(&mut self, input: &Str) -> Str ! ToolError}
because in the plugin, built with `brass build --plugin wordcount.brass`export fn create() -> Box<dyn tool.Tool> { return Box.new(WordCount { calls: 0 })}
because in the hostimport fsimport pluginlet lib = try plugin.load(&fs.files(), &"./wordcount.so")let mut t: Box<dyn tool.Tool> = try lib.call("create")export fnmarks a plugin’s entry points; they cannot be generic or declare errors (methods of the trait objects they return can). A plugin has no top-level statements.lib.call("name", args...)is typed by what the caller expects. Every export carries a fingerprint of its signature and of every type reachable from it (field by field, variant by variant, trait method by method); a mismatch, a missing export, a plugin built by another compiler or a missing file is aPluginError, never a crash.- Values move freely between host and plugin: the plugin uses the host’s allocation accounting and panic state, error tags are hashes of module and type name so both sides agree, and trait objects carry their own vtables.
- Plugins are never unloaded: values they handed out point into their code.
- Loading a plugin runs its native code with full trust; there is no sandbox.
So
plugin.loadtakes a file permission (&fs.Files), like reading the file would: code that was not handed one cannot load native code.