mmomtchev / swig

This is SWIG JavaScript Evolution, a fork of the SWIG project with modern JavaScript/TypeScript support including WASM and async
http://www.swig.org
Other
7 stars 0 forks source link

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

Open mmomtchev opened 4 months ago

mmomtchev commented 4 months ago

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;
});