#[repr(C)]pub struct HostApi {Show 14 fields
pub abi_version: u32,
pub ctx: *mut c_void,
pub register_builtin: extern "C" fn(host: *const HostApi, name: *const c_char, handler: BuiltinFn) -> c_int,
pub print: extern "C" fn(host: *const HostApi, text: *const c_char),
pub eval: extern "C" fn(host: *const HostApi, code: *const c_char) -> c_int,
pub getvar: extern "C" fn(host: *const HostApi, name: *const c_char) -> *mut c_char,
pub setvar: extern "C" fn(host: *const HostApi, name: *const c_char, value: *const c_char) -> c_int,
pub free_cstring: extern "C" fn(host: *const HostApi, s: *mut c_char),
pub register_completion: extern "C" fn(host: *const HostApi, cmd: *const c_char, generator: *const c_char) -> c_int,
pub getfunction: extern "C" fn(host: *const HostApi, name: *const c_char) -> *mut c_char,
pub addfunction: extern "C" fn(host: *const HostApi, name: *const c_char, body: *const c_char) -> c_int,
pub register_compfn: extern "C" fn(host: *const HostApi, name: *const c_char, handler: CompFn) -> c_int,
pub comp_dispatch: extern "C" fn(host: *const HostApi, name: *const c_char, argc: usize, argv: *const *const c_char) -> c_int,
pub empty_command_hash: extern "C" fn(host: *const HostApi),
}Expand description
The host API table handed to the plugin. Every field is a C-ABI
function pointer into zshrs. Layout is frozen by ABI_VERSION.
A single instance lives for the whole process; plugins may store the
*const HostApi they are given and call through it from any builtin.
Fields§
§abi_version: u32Must equal ABI_VERSION. Checked by the plugin’s own
declare_plugin! glue before it trusts the rest of the table.
ctx: *mut c_voidReserved for the host; opaque to plugins. Currently null.
register_builtin: extern "C" fn(host: *const HostApi, name: *const c_char, handler: BuiltinFn) -> c_intRegister a command name → handler. Returns 0 on success. Names
registered here resolve as commands in the shell (after real
builtins, before PATH lookup). name is copied by the host.
print: extern "C" fn(host: *const HostApi, text: *const c_char)Write text to the shell’s stdout (no trailing newline added).
eval: extern "C" fn(host: *const HostApi, code: *const c_char) -> c_intEvaluate a fragment of shell code in the host and return its exit
status. code is UTF-8, NUL-terminated.
getvar: extern "C" fn(host: *const HostApi, name: *const c_char) -> *mut c_charRead a shell scalar parameter by name. Returns a freshly
allocated C string the caller MUST release with free_cstring,
or null if the parameter is unset.
setvar: extern "C" fn(host: *const HostApi, name: *const c_char, value: *const c_char) -> c_intSet a shell scalar parameter. Returns 0 on success.
free_cstring: extern "C" fn(host: *const HostApi, s: *mut c_char)Release a string previously returned by getvar.
register_completion: extern "C" fn(host: *const HostApi, cmd: *const c_char, generator: *const c_char) -> c_intRegister a native completion for command cmd. generator names
a builtin that prints one candidate per line for the current word
(see Host::add_match). The host wires it into zsh’s completion
system (compsys) lazily — the actual compdef runs the first time
completion fires, at a safe point in the completion pipeline, so
this is cheap and safe to call from znative_init. Returns 0
on success. (ABI v2.)
getfunction: extern "C" fn(host: *const HostApi, name: *const c_char) -> *mut c_charRead a shell function’s body by name — the same deparsed text
${functions[name]} yields (one statement per line, tab-indented;
builtin autoload -X… for an autoload stub). Returns a freshly
allocated C string the caller MUST release with free_cstring, or
null if no such function is defined. This is the only structured
read of a function; getvar reads scalars, eval returns only a
status. (ABI v3.)
addfunction: extern "C" fn(host: *const HostApi, name: *const c_char, body: *const c_char) -> c_intDefine (or replace) a shell function name with body — exactly
like functions[name]=body: the body is parsed and installed in
shfunctab, so a subsequent getfunction returns its deparsed
form and the shell can call it (as a command, ZLE widget, hook,
…). Returns 0 on success, non-zero if body fails to parse.
(ABI v3.)
register_compfn: extern "C" fn(host: *const HostApi, name: *const c_char, handler: CompFn) -> c_intRegister a native override for the compsys function name (a
_NAME, e.g. _command_names). Once registered, the host’s
completion router dispatches handler in place of the built-in
Rust port or the autoloaded shell function. Returns 0 on success.
name is copied by the host. (ABI v4.)
comp_dispatch: extern "C" fn(host: *const HostApi, name: *const c_char, argc: usize, argv: *const *const c_char) -> c_intInvoke a compsys function name (e.g. _alternative, _path_commands)
with argv[0..argc] as its arguments — the host resolves it exactly
as the completer chain would (native port, then shell autoload), in
the current completion scope so local/tag state nests correctly.
Returns the function’s status. This is how an overriding
CompFn delegates the bulk of its work. (ABI v4.)
empty_command_hash: extern "C" fn(host: *const HostApi)Empty the shell’s command-name hash (cmdnamtab), the observable
effect of local -a +h path; local -A +h commands inside a
completion function: a subsequent compadd -k commands then adds
nothing until the hash refills. Used by an overriding
_command_names to reproduce the customized shadow. (ABI v4.)