Function in ffi compiler

invoke

fn invoke<A, T>(int lib, int fn_id, A args) -> Result<T, Error>
Import
use ffi::{invoke};
Source: compiler/src/builtin_docs/ffi.hy

Calls a function registered with declare, passing the tuple args.

The arguments are converted to C according to the declared tags. The result type comes from the declare return tag (unit for Void) when the compiler can trace fn_id back to its declare. Returns Err with ErrorKind::ArityMismatch for a wrong argument count, or ErrorKind::InvalidHandle for an unknown handle or id.

Native code runs with the full privileges of the process and is not checked: a wrong signature or pointer can crash the program.

Parameters#

NameType
libint
fn_idint
argsA

Returns#

Result<T, Error>

Examples#

use ffi::{dload, declare, invoke};
use ffi::types::{Int};

let lib = dload("sum")?;
let sum_id = declare(lib, "sum", (Int, Int), Int)?;
let n = invoke(lib, sum_id, (40, 2))?; // 42

See also#

↑ ↓ navigate ↵ open