-
Notifications
You must be signed in to change notification settings - Fork 79
Node.js native module programming
bellbind edited this page Oct 13, 2013
·
11 revisions
- Application codes should be removed any node.js and v8 related definitions.
- it can use another languages for application code. e.g. C, Objective-C
- Node.js plug codes are almost for convert arguments and result.
3 Handle (smart pointer) type exists
-
Handle
: as smart pointer of RAII (release the holding resource by its destructor) -
Local
: automatically managed byHandleScope
-
Persistent
: explicitly call Dispose() to release
HandleScope
instance is stacked memory manager for Local
handle.
-
HandleScope scope
: make scope upon top ofHandleScope
stack. -
Local<...> v = ...
: managed by stack top scope. the scope destructor release all managed handle -
return scope.Close(localHandle)
: unmanage alocalHandle
object on thescope
, then returnlocalHandle
asHandle
-
char*
=>String
:String::New(s)
orString::NewSymbol(s)
-
String
=>char*
:String::Utf8Value utf8(str); char* s = *utf8;
-
int32_t
=>Integer
:Integer::New(i)
-
Integer
=>int32_t
:v->Int32Value()
-
uint32_t
=>Integer
:Integer::NewFromUnsigned(i)
-
Integer
=>uint32_t
:v->Uint32Value()