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

Using lambda or function pointer for JS-callback #14

Open
Maixmko opened this issue Jul 25, 2020 · 1 comment
Open

Using lambda or function pointer for JS-callback #14

Maixmko opened this issue Jul 25, 2020 · 1 comment

Comments

@Maixmko
Copy link

Maixmko commented Jul 25, 2020

From your example:

auto cb = (std::function<void(const std::string&)>) context.eval("my_callback");

is it possible instead to use lambda or function pointer? I tried

auto cb = (void(*)(const std::string&)) context.eval("my_callback");

It compiles, but on run gives TypeError: <null> object expected.

@ftk
Copy link
Owner

ftk commented Jul 28, 2020

You can't convert to function pointer. Now it's possible to convert to lambda:

auto cb = (std::function<void(const std::string&)>) context.eval("my_callback"); // cb is std::function
auto cb = context.eval("my_callback").as<std::function<void(const std::string&)>>(); // cb is lambda

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

2 participants