From dea43a0244e61f6401b0ee2476eb26868ec59aba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bennet=20Ble=C3=9Fmann?= Date: Thu, 17 Jul 2025 01:45:13 +0200 Subject: [PATCH] update docs --- src/lib/ffi.pl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/ffi.pl b/src/lib/ffi.pl index cce60ff6..165d5d04 100644 --- a/src/lib/ffi.pl +++ b/src/lib/ffi.pl @@ -11,8 +11,8 @@ The main predicate is `use_foreign_module/2`. It takes a library name (which dep operating system could be a `.so`, `.dylib` or `.dll` file). and a list of functions. Each function is defined by its name, a list of the type of the arguments, and the return argument. -Types available are: `sint8`, `uint8`, `sint16`, `uint16`, `sint32`, `uint32`, `sint64`, -`uint64`, `f32`, `f64`, `cstr`, `void`, `bool`, `ptr` and custom structs, which can be defined +Types available are: `sint8`/`i8`, `uint8`/`u8`, `sint16`/`i16`, `uint16`/`u16`, `sint32`/`i32`, `uint32`/`u32`, `sint64`/`i64`, +`uint64`/`u64`, `f32`, `f64`, `cstr`, `void`, `bool`, `ptr` and custom structs, which can be defined with `foreign_struct/2`. After that, each function on the lists maps to a predicate created in the ffi module which @@ -27,6 +27,12 @@ ffi:FUNCTION_NAME(+InputArg1, ..., +InputArgN, -ReturnArg). % for all return typ ffi:FUNCTION_NAME(+InputArg1, ..., +InputArgN). % for void and bool ``` +## Notes regarding cstr + +- When using `cstr` as an argument type the string will be deallocated once the function returns. +- When using `cstr` as a return type the string will be copied and won't be deallocated. + + ## Example For example, let's see how to define a function from the [raylib](https://www.raylib.com/) library. -- 2.54.0