From 028ebea5b8d70110d5dd20ea4f95e63fbb295f23 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Sat, 25 Sep 2021 08:24:04 -0500 Subject: [PATCH] Add section about other compound types --- README.md | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 97a3e05..c04c3b2 100644 --- a/README.md +++ b/README.md @@ -103,15 +103,35 @@ macro `defalias` is used to define a struct alias. "zero" [] ::point) ``` -In addition to structs, there is also support for passing Clojure functions as -callbacks to native functions, as well as calling function pointers returned -from native functions as Clojure functions. +In cases where a pointer to some data is required to pass as an argument to a +native function, but dosn't need to be read back in, the `pointer` primitive +type can take a type argument. ```clojure -(defcfn higher-order - "higher_order" [[::ffi/fn [::ffi/c-string] ::ffi/int]] ::ffi/int) +[::ffi/pointer ::ffi/int] ``` +Arrays are also supported via a type argument. Keep in mind that they are the +array itself, and not a pointer to the array like you might see in certain cases +in C. + +```clojure +[::ffi/array ::ffi/int 3] +``` + +In addition to these compound types, there is also support for Clojure +functions. + +```clojure +[::ffi/fn [::ffi/c-string] ::ffi/int] +``` + +Be aware though that if an exception is thrown out of a callback that is called +from C, the JVM will crash. The resulting crash log should include the exception +type and message in the registers section, but it's important to be aware of all +the same. Ideally you should test your callbacks before actually passing them to +native code. + TODO Talk about writing your own serdes ## License