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

Provide a built-in helper that handles calling into JS with both async and sync support #36

Open
mmomtchev opened this issue Mar 1, 2024 · 0 comments

Comments

@mmomtchev
Copy link
Owner

Provide a helper that handles calling into JS behind the scenes and supports both sync and async mode.

Something along the lines of:

SWIG_NAPI_Call(js_callback, [](std::vector<napi_value> &js_args, int passcode, const std::string &name){
    $typemap(out, int, 1=passcode, result=js_args.at(0), argnum=callback argument 1);
    $typemap(out, std::string, 1=name, result=js_args.at(1), argnum=callback argument 2);
}, [](std::vector<napi_value> &js_args){
    Napi::Value js_ret = js_callback.Call(env.Undefined(), js_args);
}, [](){
    std::string c_ret;
    $typemap(in, std::string, input=js_ret, 1=c_ret, argnum=JavaScript callback return value)
    return c_ret;
});
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

1 participant