Code Monkey home page Code Monkey logo

node-addon-examples's Introduction

Node.js Addon Examples

See the Node.js C++ addons page for details of the examples here.

In each directory, run:

$ node-gyp rebuild
$ node ./

See the v0.11 branch for updated examples applicable to Node v0.11 and above.

Compatibility notes

Node v0.11: V8 requires current isolate

The V8 upgrade that occured when v0.11 was released requires that the current isolate be passed to scope creation calls and most New() calls.

Isolate* isolate = Isolate::GetCurrent();
// ...
HandleScope scope(isolate);
// ...
Persistent<Function> constructor = Persistent<Function>::New(isolate, tpl->GetFunction());

Omission of the current isolate will only trigger a compile-time warning at this stage but addon authors wishing to remove those warnings and remain backward-compatible with v0.10 and prior may need to get creative with macros:

// NODE_MODULE_VERSION was incremented for v0.11

#if NODE_MODULE_VERSION > 0x000B
#  define MY_NODE_ISOLATE_DECL Isolate* isolate = Isolate::GetCurrent();
#  define MY_NODE_ISOLATE      isolate
#  define MY_NODE_ISOLATE_PRE  isolate, 
#  define MY_NODE_ISOLATE_POST , isolate 
#  define MY_HANDLESCOPE v8::HandleScope scope(MY_NODE_ISOLATE);
#else
#  define MY_NODE_ISOLATE_DECL
#  define MY_NODE_ISOLATE
#  define MY_NODE_ISOLATE_PRE
#  define MY_NODE_ISOLATE_POST
#  define MY_HANDLESCOPE v8::HandleScope scope;
#endif

MY_NODE_ISOLATE_DECL
MY_HANDLESCOPE

// ...

Persistent<Function> constructor = Persistent<Function>::New(MY_NODE_ISOLATE_PRE tpl->GetFunction());

node-addon-examples's People

Contributors

rvagg avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.