Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapping std::function<void()> #270

Open
gstavrinos opened this issue Oct 18, 2020 · 3 comments
Open

Wrapping std::function<void()> #270

gstavrinos opened this issue Oct 18, 2020 · 3 comments

Comments

@gstavrinos
Copy link

Just a heads-up, I am trying to wrap a function that takes an std::function<void()> as an argument, and I get the following error. Seems like it has not been wrapped yet.

No appropriate factory for type St8functionIFvvEE
ERROR: LoadError: No appropriate factory for type St8functionIFvvEE
@gstavrinos gstavrinos changed the title std::function Wrapping std::function<void()> Oct 18, 2020
@sloede
Copy link
Contributor

sloede commented Nov 30, 2024

I have a similar question: Is it possible to wrap a function that on the C++ side expects an argument of type std::function<double(double)> func, and which I can then feed a Julia function?

@barche
Copy link
Collaborator

barche commented Nov 30, 2024

There is no direct conversion from Julia functions to std::function. You can use jlcxx::SafeCFunction or jl_function_t* as arguments to wrapper functions, and then use these to create a C++ lambda that is passed on to the function taking an std::function. There are examples of this in the functions.cpp example in libcxxwrap-julia.

Leaving this open since it may actually be possible to automatically do the conversion from jl_function_t* to std::function automatically, with some work.

@sloede
Copy link
Contributor

sloede commented Nov 30, 2024

Thanks a lot for the quick feedback @barche. I also found this section in the docs, which also sheds some light on it. This should allow me to achieve what I need to do - and with acceptable coding overhead. Great work with CxxWrap.jl, as usual 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants