invoke
fn invoke<A, T>(int lib, int fn_id, A args) -> Result<T, Error> Import
Source: use ffi::{invoke}; 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#
| Name | Type |
|---|---|
lib | int |
fn_id | int |
args | A |
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#
ffi::declareunitffi::ErrorKinddload: Loads a native shared library and returns a handle to it.read_ints: Copiescount64-bit integers (int64_t) from native memory atptr.