declare
fn declare<A, R>(int lib, string name, A arg_types, R ret_type, bool variadic) -> Result<int, Error> Import
Source: use ffi::{declare}; 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#
| Name | Type |
|---|---|
lib | int |
name | string |
arg_types | A |
ret_type | R |
variadic | bool |
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#
ffi::typesintfloatstringffi::invokeffi::ErrorKinddload: Loads a native shared library and returns a handle to it.read_ints: Copiescount64-bit integers (int64_t) from native memory atptr.