moonbit-docs icon indicating copy to clipboard operation
moonbit-docs copied to clipboard

docs: improve FFI `callee-owned calling convention` documentations for calling `closure`

Open illusory0x0 opened this issue 6 months ago • 3 comments

we can bind this C function and pass closure to it using the following trick:

current moonc insert moonbit_incref ouside the closure, but in FFI boundary moonc insert this instruction is impossible.

a possible solutiion is insert this instruction inside the closure BLOCK BEGIN, and then insert moonbit_decref in the closure BLOCK END. like C++ RAII.

example

reproduce step

moonbit-docs ffi trick

illusory0x0 avatar Apr 21 '25 15:04 illusory0x0