Function in ffi compiler

declare

fn declare<A, R>(int lib, string name, A arg_types, R ret_type, bool variadic) -> Result<int, Error>
Import
use ffi::{declare};
Source: compiler/src/builtin_docs/ffi.hy

Looks up the C function name in a loaded library and records its signature.

arg_types is a tuple of FFI type tags from ffi::types ((Int, Ptr), or () for none), and ret_type is one tag (Void for no result). Bare names (int, float, string, void) and extern struct types are accepted too. Pass true as the optional fifth argument for a C variadic function such as printf: arg_types is then the fixed prefix.

Returns the function id for invoke, or Err with ErrorKind::SymbolNotFound, Libffi or InvalidSignature.

Parameters#

NameType
libint
namestring
arg_typesA
ret_typeR
variadicbool

Returns#

Result<int, Error>

Examples#

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

fn add(int a, int b) -> Result<int, Error> {
    let lib = dload("sum")?;
    let sum_id = declare(lib, "sum", (Int, Int), Int)?;
    return invoke(lib, sum_id, (a, b));
}

See also#

↑ ↓ navigate ↵ open