Here's an extended example of an API that is designed specifically to
expose Julia functions to be called from C and Python:

https://github.com/mlubin/cmpb/blob/master/src/cmpb.c


As far as defining functions without "names", on 0.5-dev anonymous
functions work fine with `cfunction`:


julia> entry_ptr = cfunction( (x, ptr) -> ccall(ptr, Int, (Int,), x), Int,
(Int, Ptr{Void}) )
Ptr{Void} @0x0000000317ee4c60

julia> cb_ptr = cfunction( y -> y^2, Int, (Int,))
Ptr{Void} @0x0000000317ee80c0

julia> myf(x) = ccall(entry_ptr, Int, (Int, Ptr{Void}), x, cb_ptr)
myf (generic function with 1 method)

julia> myf(4)
16


On Tue, Jul 5, 2016 at 7:02 PM, Jeff <[email protected]> wrote:

> Hi all,
>
>
> I'd like to call a Julia function from C++. This Julia function takes
> another Julia function as an argument (a callback function). I'd like to
> write this callback function entirely in C++ too, and pass it directly to
> Julia, without declaring a global name for it in Julia's name space (like
> how ints, floats, etc. are passed from C++ to Julia wo creating top-level
> names for them in Julia). Presumably the arguments to my C++ implementation
> of the callback function will havejl_value_t * as their types.
>
> Can anyone show me how to do this?
>
>
> I tried posting this question on stackoverflow originally but I didn't get
> an answer.
>
>
> https://stackoverflow.com/questions/38135749/calling-a-julia-function-from-c-that-takes-a-julia-callback-function-as-an-arg
>
>
> Thanks much!
>
>
> Jeff
>
>
>

Reply via email to