OxL Reference

module std.ffi

std.ffi — helpers for the C FFI (§16.1, D-1500..D-1510). Intrinsics: compiler/src/codegen/CGFfi.cpp.

str and the other managed types never cross the C boundary directly. Strings go through CString (owned, NUL-terminated) and CStr.fromPtr; raw pointers *T / *var T are used inside unsafe with the methods below; null<T>() and zeroed<T>() build the null pointer and an all-zero @c_layout value.

Example:

oxl✓ checked in CI
import c "stdlib.h" { atoi }

fn main() io {
  let text = "42".toCString()
  print("{unsafe { atoi(text.asPtr()) } + 1}")
}
Output
43

Types

data CStrNamespace of helpers for reading C strings.
data CStringOwned, NUL-terminated copy of a str for passing to C (const char *).
type Listtype alias · std.ffi
type strtype alias · std.ffi
type Ttype alias · std.ffi
type var Ttype alias · std.ffi

Functions

nullThe null pointer.
sizeOfsizeof(T) in bytes with C layout rules.
zeroBytesA list of n zero bytes
zeroedAn all-zero value of a @c_layout type (C memset(&x, 0, sizeof x)); used to initialise out-parameters.

See also