Provide a built-in helper that handles calling into JS with both async and sync support
Opened this issue · 0 comments
mmomtchev commented
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;
});