Add segment in readme about anonymous functions as callbacks
This commit is contained in:
parent
e9a5b640ac
commit
c9f30a361c
1 changed files with 7 additions and 0 deletions
|
|
@ -239,6 +239,13 @@ 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
|
the same. Ideally you should test your callbacks before actually passing them to
|
||||||
native code.
|
native code.
|
||||||
|
|
||||||
|
Another important thing to keep in mind is the expected lifetime of the function
|
||||||
|
that you pass to native code. For example it is perfectly fine to pass an
|
||||||
|
anonymous function to a native function if the callback will never be called
|
||||||
|
again once the native function returns. If however it saves the callback for
|
||||||
|
later use the JVM may collect it prematurely, causing a crash when the callback
|
||||||
|
is later called by native code.
|
||||||
|
|
||||||
### Variadic Functions
|
### Variadic Functions
|
||||||
Some native functions can take any number of arguments, and in these cases coffi
|
Some native functions can take any number of arguments, and in these cases coffi
|
||||||
provides `vacfn-factory` (for "varargs C function factory").
|
provides `vacfn-factory` (for "varargs C function factory").
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue