OxL Reference

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.

sh
oxl run examples/ffi-demo
oxl test examples/ffi-demo

What 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 pure with unsafe { … } inside is the safe interface.
  • export c fn compareInts(a: *u8, b: *u8) -> i32 is a function with the C ABI whose name is passed to qsort as a pointer.
  • Third-party libraries: [deps] zlib = { c = "system", header = "zlib.h" } in oxl.toml adds -lz to the link line.

Project files · Download (zip)