GithubHelp home page GithubHelp logo

nodejs / abi-stable-node-addon-examples Goto Github PK

View Code? Open in Web Editor NEW
239.0 239.0 64.0 152 KB

Node Add-on Examples with PoC ABI stable API for native modules

Python 10.24% C++ 77.73% JavaScript 11.25% C 0.78%
node nodejs

abi-stable-node-addon-examples's People

Contributors

birdca avatar daninet avatar debuggings avatar jimihford avatar mhdawson avatar nicknaso avatar rvagg avatar shonfrazier avatar watson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

abi-stable-node-addon-examples's Issues

No matching version found for [email protected] while npm install on 1_hello_world\node-api

When I tried the example of 1_hello_world\node-api, I first run npm install, and then it gave me the following errors. I also looked the https://www.npmjs.com/package/node-api, but it seems not this package.

D:\code\node\abi-stable-node-addon-examples\1_hello_world\node-api>npm install
npm WARN npm npm does not support Node.js v10.0.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
npm WARN npm You can find the latest version at https://nodejs.org/
npm ERR! code ETARGET
npm ERR! notarget No matching version found for [email protected]
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'hello_world'
npm ERR! notarget

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Liu.D.H\AppData\Roaming\npm-cache\_logs\2018-04-25T05_33_59_261Z-debug.log

6_object_wrap/napi - Destructor not called?

Hi,

I've been toying with these examples for sometime (as my introduction to node.js from c++ side) and noticed something peculiar that I'm not sure is the expected behavior.

In Example 6 (N-API), I cannot confirm that the created c++ objects are ever destructed. Here is what I've done:

At the top of myobject.cc, I added

#include <fstream>
std::ofstream os("test.txt",std::fstream::out); // defined globally

Then, in MyObject's constructor and destructor as well as in New() and Destructor() member functions I inserted at the top of each function:

os << "MyObject::XXX" << std::endl;  // XXX is 'MyObject', '~MyObject', 'New' or 'Destructor'

I expect executing node ./addon.js creates test.txt with 2 sets of the 4 unique MyObject::XXX lines. (In my novice node.js eyes, it should create 2 instances of the c++ class.) However, the generated test.txt looks like

MyObject::New
MyObject::MyObject
MyObject::New
MyObject::MyObject
MyObject::New
MyObject::MyObject
MyObject::New
MyObject::MyObject

This output suggests 4 c++ instantiations and none of them being destructed. Is this a bug or lack of my understanding of how things work in this framework?

Thanks
Kesh

Provide examples (NAPI) creating multiple properties

Curent examples cover cases only with 1 properties get created inside Init.
Is any chance to give examples how to create multiple properties?

next approach is incorrect - it's overwrite exports


napi_value Init(napi_env env, napi_value exports) {
  napi_status status;
  napi_value fn;
  
  read_dht_data();

  status = napi_create_function(env, NULL, 0, myGetTemp, NULL, &fn);
  if (status != napi_ok) {
    napi_throw_error(env, NULL, "Unable to wrap native function");
  }

  status = napi_set_named_property(env, exports, "getTemp", fn);
  if (status != napi_ok) {
    napi_throw_error(env, NULL, "Unable to populate exports");
  }

status = napi_create_function(env, NULL, 0, myGetTemp2, NULL, &fn);
  if (status != napi_ok) {
    napi_throw_error(env, NULL, "Unable to wrap native function");
  }

  status = napi_set_named_property(env, exports, "getTemp2", fn);
  if (status != napi_ok) {
    napi_throw_error(env, NULL, "Unable to populate exports");
  }

  return exports;
}

Bug in napi folder

There in .js file must be simply require without ('addon'). Segmentation fault.

Experimental feature warning

When running my N-API code I get this warning

(node:21984) Warning: N-API is an experimental feature and could change at any time.

This is a nuisance. Can we have an API call to disable the warning message if we dont want it ?

By the way, I like N-API

Why use assert?

Hello guys!

Why does every example use asserts instead of if checks & maybe some exceptions?
Wouldn't it be better to just throw errors so the js code has the opportunity to recover from possible errors and only use asserts for testing etc?

P.S.: Thanks for all the examples. You guys really helped me understand all the APIs!

pass Buffer as argument

Hi, I have problem figuring out, how to pass buffer from process Buffer argument in node-api-addon into Napi:Buffer<uint8_T>.
This is old non-napi snippet:

    Local<Object> data = args[0]->ToObject();

    if(!Buffer::HasInstance(data))
        return except("Argument should be a buffer object.");

    char * input = Buffer::Data(data);

I tryed:

   Napi::Buffer<uint8_t> input_data = info[0].As<Napi::Buffer<uint8_t>>();

which fails to compile with error, that As does not contain overload for converting to Napi::Buffer<uint8_t>. There is also no ToBuffer function.

So I ended up with casting to Napi::Object :

   Napi::Object input_data = info[0].As<Napi::Object>();

But this can not be cast to Napi::Buffer<uint8_t> directly. So I´m looking for example, how to handle this situation - to get from Napi::Value parameter/argument specific Napi::Buffer<T>.

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.