docs

std::plugin

本頁內容

API 參考只有英文版,由標準函式庫原始碼中的英文文件註解產生。

load a plugin into this program and call its functions.

A plugin is a package built with lib: { kind: "plugin" }. It shares this program's runtime: what it returns are ordinary values here (str, List, closures, any, sums), and a type of a package both use is the same type on both sides.

nabi
let p = try plugin::load(plugin::beside("enemies"));
let spawn = try p.get::<fn(i32) -> List<str>>("enemies::spawn");
println(spawn(3).len());

Structs

PluginSource

pub struct Plugin

A loaded plugin. Copies name the same plugin.

  • pub fn name(self) -> str§

    Source

    Its package name.

  • pub fn version(self) -> str§

    Source

    Its package version.

  • pub fn path(self) -> str§

    Source

    The file it was loaded from.

  • pub fn get<F>(self, path: str) throws (PluginError) -> F§

    Source

    The function path ("enemies::spawn"), of type F: a pub fn of the plugin's package declared with exactly that type.

  • pub fn get_static<T>(self, path: str) throws (PluginError) -> T§

    Source

    The value of static path ("enemies::LEVEL") of type T.

  • pub fn types(self) -> List<TypeInfo>§

    Source

    The types it describes: those its code asks core::reflect about and the types they are made of. Do not use one after the plugin is unloaded.

  • pub fn unload(self) -> Unload§

    Source

    Stop finding it, and unload it once nothing of it is alive: no value of its types, no function of it held or running, no plugin using it.

Enums

UnloadSource

pub enum Unload

What Plugin::unload did.

  • Unloaded: nothing of it was alive.

  • Pending(str)§

    Source

    No longer found by get; it goes once nothing of it is alive. The text says what still holds it.

  • Kept(str)§

    Source

    Stays loaded: the text says why.

PluginErrorSource

pub enum PluginError

Why a plugin did not load, or an item was not found. Each message says what to do.

  • NotFound§

    Source

    No file at path.

  • NotAPlugin§

    Source

    The file is not a Nabi plugin (a C library, a program).

  • Toolchain§

    Source

    Built by another toolchain than this program.

  • Target§

    Source

    Built for another target than this program.

  • MissingPackages§

    Source

    Packages the plugin takes from the program, which has none of them.

  • MissingSymbols§

    Source

    Items the plugin takes from the program, which has none of them.

  • A type the program and the plugin both have is laid out differently (built with other features).

  • NoSuchItem§

    Source

    The plugin has no pub fn (or static) at path.

  • WrongType§

    Source

    path has another type than the one asked for: have (empty when unknown).

  • NotLoaded§

    Source

    The plugin was unloaded.

  • The system loader failed.

  • pub fn message(self) -> str§

    Source

    What went wrong and what to do, for display.

Trait implementations 1

Functions

fileSource

pub fn file(name: str) -> str

The file name a plugin package name builds to on this target: libname.dylib, libname.so or name.dll.

besideSource

pub fn beside(name: str) -> str

The path of plugin name's file beside this program's executable: where nabi build puts a plugin: true dependency.

loadSource

pub fn load(path: str) throws (PluginError) -> Plugin

Load the plugin at path (a bare file name is in the current directory). Loading one that is loaded gives the same plugin.

loadedSource

pub fn loaded() -> List<Plugin>

The plugins loaded and not unloaded, in load order.

wait_unloadedSource

pub fn wait_unloaded(p: Plugin, ms: u64) -> bool

Wait until p is unloaded for good (Unload::Pending), at most ms milliseconds, collecting garbage meanwhile; whether it is.