ffi-demo
Integration with C (§16.1): the compiler reads a header through libclang and maps C types to OxL types (double →
f64, int → i32, pointers → *T). A call of a foreign function is allowed only in unsafe, so the package hides it behind an
ordinary function.
oxl run examples/ffi-demo
oxl test examples/ffi-demoWhat to look at:
import c "math.h" { sqrt, pow }and@nonblocking: the call does not go to the pool of blocking threads.fn hypot(…) -> f64 purewithunsafe { … }inside is the safe interface.export c fn compareInts(a: *u8, b: *u8) -> i32is a function with the C ABI whose name is passed toqsortas a pointer.- Third-party libraries:
[deps] zlib = { c = "system", header = "zlib.h" }inoxl.tomladds-lzto the link line.