Skip to content

Commit

Permalink
doc: update example in module registration
Browse files Browse the repository at this point in the history
Update return type of `Init` function in documentation to match
`napi_addon_register_func` signature. Return type used to be
`void`, now it is `napi_value`.

PR-URL: nodejs#17424
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
fhinkel authored and Gabriel Schulhof committed Apr 16, 2018
1 parent 45a3e6b commit d9dc130
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2877,15 +2877,17 @@ napi_value SayHello(napi_env env, napi_callback_info info) {
return nullptr;
}

void Init(napi_env env, napi_value exports, napi_value module, void* priv) {
napi_value Init(napi_env env, napi_value exports) {
napi_status status;

napi_value fn;
status = napi_create_function(env, NULL, SayHello, NULL, &fn);
if (status != napi_ok) return;
status = napi_create_function(env, nullptr, 0, SayHello, nullptr, &fn);
if (status != napi_ok) return nullptr;

status = napi_set_named_property(env, exports, "sayHello", fn);
if (status != napi_ok) return;
if (status != napi_ok) return nullptr;

return exports;
}

NAPI_MODULE(addon, Init)
Expand Down

0 comments on commit d9dc130

Please sign in to comment.