static napi_value TransObject(napi_env env, napi_callback_info info) {
napi_status status;
size_t argc = 1;
napi_value js_cb;
status = napi_get_cb_info(env, info, &argc, &js_cb, nullptr, nullptr);
assert(status == napi_ok);
napi_value onCallBack1, str_arg;
status = napi_get_named_property(env, js_cb, "onCallBack1", &onCallBack1);
assert(status == napi_ok);
status = napi_create_string_utf8(env, "mangguo", strlen("mangguo"), &str_arg);
assert(status == napi_ok);
size_t cb1argc = 1;
status = napi_call_function(env, js_cb, onCallBack1, cb1argc, &str_arg, nullptr);
size_t cb2argc = 1;
napi_value onCallBack2, int_arg;
status = napi_get_named_property(env, js_cb, "onCallBack2", &onCallBack2);
status = napi_create_int32(env, 2, &int_arg);
assert(status == napi_ok);
status = napi_call_function(env, js_cb, onCallBack2, cb2argc, &int_arg, nullptr);
assert(status == napi_ok);
napi_value oncallback3, arg_object;
status = napi_get_named_property(env, js_cb, "onCallBack3", &oncallback3);
assert(status == napi_ok);
status = napi_create_object(env, &arg_object);
assert(status == napi_ok);
napi_value testNum, testString;
status = napi_create_int32(env, 123, &testNum);
assert(status == napi_ok);
status = napi_set_named_property(env, arg_object, "testNum", testNum);
assert(status == napi_ok);
status = napi_create_string_utf8(env, "mangguo", strlen("mangguo"), &testString);
assert(status == napi_ok);
status = napi_set_named_property(env, arg_object, "testString", testString);
assert(status == napi_ok);
status = napi_call_function(env, js_cb, oncallback3, cb2argc, &arg_object, nullptr);
assert(status == napi_ok);
return nullptr;
}
导入:import testNapi from ‘libentry.so’;
使用:testNapi.transobject(tscb);