-
The npm package file:
package.json- "name", "version", "description", "license", "repository":
for warning inhibition (also add a
readmevariant file) - "main": in this case, use
out/Release/xxx.nodeshared object directly - "dependencies": use "nan-2" as dependency
- "name", "version", "description", "license", "repository":
for warning inhibition (also add a
-
The native module build description file:
binding.gyp- "targets" - "include_dirs": for including nan headers as
<nan.h> - "targets" - "target_name"; set name xxx for
out/Release/xxx.node - "targets" - "sources"; list of C/C++ source files for the target
- "targets" - "condition" - "cflags": for set clang/gcc options
- "targets" - "include_dirs": for including nan headers as
-
A module main source: e.g.
nan-example.ccNAN_METHOD(name): generic declaration of native functioninfo: the argument ofNAN_METHODdeclaration asv8::FunctionCallbackInfo
info.GetReturnValue().Set(...): current style ofreturn ...as in JS functionNAN_MODULE_INIT(name): generic declaration of module entry functiontarget: reference ofexportsobject for the module
NAN_EXPORT(target, funcname): add native function to the target as same nameNan::Export(target, name, func): add a function as renamed
NODE_MODULE(target_name, moduleinit):target_nameshould be same as in binding.gyp
-
Native module source detailed
Nan::To<v8type>: returnsMaybeLocal<v8type>Nan::To<cpptype>: returnsMaybe<cpptype>MaybeLocal<v8type>andMaybe<cppnumtype>: many current v8 API returns as haskell's Maybe style(Just or Nothong)MaybeLocal<v8type>#ToLocalChecked(): forcely returnsLocal<v8type>valueMaybe<cppnumtype>#FromJust(): forcely returnscppnumtypevalue
*Nan::Utf8String(v8::String): returns asconst char*stringNan::New(const char*): create asMaybeLocal<v8::String>stringNan::New(cnumtype): create asLocal<v8::NUMTYPE>object (e.g.int32_tasLocal<v8::Int32>, notMaybeLocal)
-
Detail for throwing Error function
Nan::Error(const char*): createLocal<v8::Error>objectNan::ThrowError(error): throw exception (and you shouldreturnthe function)- call current isolate (e.g.
info.GetIsolate()orv8::Isolate::getCurrrent())v8::Isolate#ThrowException(error)inside
- call current isolate (e.g.
-
Detail for callback function
- use
v8::Object#CallAsFunction(recv, argc, argv)- returns
Local<Value> - [NOTE] recv of
Nan::CallAsFunctionis onlyv8::Object(cannot accept null value)
- returns
- use
-
Detail of TypedArray
- at first cleate
v8::ArrayBufferthen createv8::Int32Array - access data as usual
v8::Object
- at first cleate
npm install
Native addon example with build system description for the Old Node-0.6 age version:
See also current info:
- GYP: https://chromium.googlesource.com/external/gyp/+/master/docs/UserDocumentation.md
- nan: https://github.com/nodejs/nan
- https://github.com/nodejs/nan/blob/master/doc/node_misc.md
- https://github.com/nodejs/nan/blob/master/doc/scopes.md
- https://github.com/nodejs/nan/blob/master/doc/methods.md
- https://github.com/nodejs/nan/blob/master/doc/new.md
- https://github.com/nodejs/nan/blob/master/doc/converters.md
- https://github.com/nodejs/nan/blob/master/doc/maybe_types.md
- https://github.com/nodejs/nan/blob/master/doc/errors.md
- https://github.com/nodejs/nan/blob/master/doc/v8_misc.md
- v8: https://developers.google.com/v8/get_started
- v8 current api: http://v8.paulfryzel.com/docs/master/
- http://v8.paulfryzel.com/docs/master/classv8_1_1_function_callback_info.html
- http://v8.paulfryzel.com/docs/master/classv8_1_1_maybe_local.html
- http://v8.paulfryzel.com/docs/master/classv8_1_1_maybe.html
- http://v8.paulfryzel.com/docs/master/classv8_1_1_isolate.html
- http://v8.paulfryzel.com/docs/master/classv8_1_1_object.html
- http://v8.paulfryzel.com/docs/master/classv8_1_1_array_buffer.html
- http://v8.paulfryzel.com/docs/master/classv8_1_1_int32_array.html
- node native addon api: https://nodejs.org/api/addons.html
- npm package.json: https://docs.npmjs.com/files/package.json