On Tuesday, May 24, 2016 at 3:01:12 PM UTC-4, Gabriel Gellner wrote:
>
> Working thru the incredible guide:
> http://julialang.org/blog/2013/05/callback
>
> I am stuck on understanding if there are any work arounds for being able 
> to use julia anonymous functions in `ccall` callback functions. 
> Specifically I am interested in the common case of wanting to use function 
> parameters without having to do the C convention of passing around a void 
> *param pointer as the last argument of the callback.
> (ie instead of having func(x, y, param) I could do (x, y) -> func(x, y, a, 
> b) to set the values for the parameters of a julia callback function that 
> is passed to a ccall routine)
>

As explained in the guide (see the qsort_r example), you only need for the 
C API to have a void* pointer that you pass around.    On the Julia side, 
this can be completely hidden from the caller.  (e.g. in the qsort_r 
example, the Julia lessthan function passed to qsort! does not need a 
"param" argument.)

(This is how NLopt.jl, Cubature.jl, etcetera work: the C API uses void* 
pointers, but this is hidden from the Julia callers exactly as described in 
the blog post.)

Reply via email to