Skip to main content

Crate generic_lang_api

Crate generic_lang_api 

Source
Expand description

§Plugin ABI and authoring API for the generic programming language

Native modules for generic are shared libraries speaking the C ABI defined in abi. Rust plugin authors use the safe layer in this crate root; other languages use the generated include/generic.h.

This crate is versioned independently from the interpreter - it tracks ABI stability for plugin authors. Build against the version matching the target interpreter (GENERIC_PLUGIN_ABI_VERSION is checked at load).

See the plugin authoring guide for worked quickstarts (Rust and C), the value model, calling back into generic, the exception model, and the rooting contract.

§Example

use generic_lang_api::{ArgValue, GenericValue, Host, PluginError};

fn add(host: &mut Host, args: &[GenericValue]) -> Result<GenericValue, PluginError> {
    match (host.decode(args[0]), host.decode(args[1])) {
        (ArgValue::Int(a), ArgValue::Int(b)) => Ok(host.make_int(a + b)),
        _ => Err(host.type_error("add expects two ints")),
    }
}

generic_lang_api::export_module![("add", &[2], add)];

Re-exports§

pub use abi::ClassDesc;
pub use abi::FfiReturn;
pub use abi::FfiStatus;
pub use abi::FfiStr;
pub use abi::FunctionDesc;
pub use abi::GENERIC_PLUGIN_ABI_VERSION;
pub use abi::GenericValue;
pub use abi::HostApi;
pub use abi::MethodDesc;
pub use abi::ModuleDesc;
pub use abi::PluginFn;
pub use abi::PluginMethodFn;
pub use abi::PluginTraverseFn;
pub use abi::PluginValueFn;
pub use abi::PluginVisitFn;
pub use abi::ValueDesc;

Modules§

abi
The raw C ABI shared between the generic interpreter and its plugins.

Macros§

export_module
Export the plugin’s functions and classes to the generic interpreter.

Structs§

Host
Safe access to the host VM for the duration of one plugin call.
Rooted
RAII guard for a rooted value; see Host::rooted.

Enums§

ArgValue
A decoded view of a GenericValue, obtained via Host::decode.
PluginError
The error side of a plugin function: what should reach the generic VM when the function does not return normally.
ValueKind
Value kinds returned by HostApi::value_kind.

Type Aliases§

RustPluginFn
Signature of a Rust plugin function used with export_module!.
RustPluginMethodFn
Signature of a Rust plugin method used with export_module!. The receiver (self) is a separate parameter; args are the remaining arguments only.
RustPluginValueFn
Signature of a Rust plugin value creator used with export_module!: builds one module constant at import time.