node.js-addon

How to return a new object from NanAsyncWorker?

别说谁变了你拦得住时间么 提交于 2019-12-11 09:57:06
问题 I'm working on a node.js/io.js native plugin, and I need to create a new native object from an async callback. Using the nan helpers, I've got something that looks like: class MyObject : public node::ObjectWrap { /* definition */ }; class MyWorker : public NanAsyncWorker { bool varForMyObject; virtual void Execute() {/* do stuff and sets varForMyObject */} virtual void HandleOKCallback() { NanScope(); MyObject* obj = new MyObject(varForMyObject); Local<Value> argv[] = { NanNull(), obj // ???

Return a Nan::ObjectWrap from another Nan::ObjectWrap

六月ゝ 毕业季﹏ 提交于 2019-12-07 08:22:07
问题 I have two subclasses of Nan::ObjectWrap class Zyre: public Nan::ObjectWrap {...} class ZyreEvent: public Nan::ObjectWrap {...} How can I return a ZyreEvent javascript object from a method in Zyre ? I have the following method, in which I create a ZyreEvent : NAN_METHOD (Zyre::_recv) { Zyre *node = Nan::ObjectWrap::Unwrap <Zyre> (info.Holder ()); ZyreEvent *zyre_event = new ZyreEvent (node->self); info.GetReturnValue().Set(zyre_event->Wrap(info.This())); } But I can't Wrap the zyre_event

Invoke javascript callback repeatedly from C++ module in node.js

我怕爱的太早我们不能终老 提交于 2019-12-06 15:36:43
So I am writing a node.js module in C++ which processes data from a camera. I want to invoke a callback function in my app.js file whenever new data is available. What I have at the moment Right now I have in my node javascript file ( app.js ) the following code. Every second it calls a function in my C++-Module and returns the number of frames that have been processed so far: setInterval(function () { var counter = MyCPPModule.NumberOfFrames(); console.log(counter); }, 1000); In my C++ file I have the following functions. 1.) I have a function to get the number of frames - the function that

Error: Cannot find module 'nan'

荒凉一梦 提交于 2019-12-06 05:01:31
问题 I'm working on native Node.js addon and following nan docs I included nan into binding.gyp like: "include_dirs" : [ "<!(node -e \"require('nan')\")" ] Also nan is in npm dependencies. But when I install the package inside the another node module node-gyp is failed with error > nnb@1.0.2 install /Users/Shopgate/sandbox/stress/node_modules/nnb > node-gyp rebuild module.js:338 throw err; ^ Error: Cannot find module 'nan' at Function.Module._resolveFilename (module.js:336:15) at Function.Module.

Node.js and C/C++ integration: how to properly implement callbacks?

ぃ、小莉子 提交于 2019-12-06 03:28:24
I am trying to implement a C++ extension to be integrated with node.js. This extension will internally invoke some blocking calls, so it needs to provide a non-blocking interface to the node.js world. As specified in https://nodejs.org/api/addons.html , there are two ways to implement non-blocking callbacks: a) By using a simple callback to a JavaScript function. So my extension would have to spawn a thread and return immediately, and let that thread call the blocking code and then invoke the JavaScript callback upon return. This seems relatively simple to implement. b) By using the libuv

Return a Nan::ObjectWrap from another Nan::ObjectWrap

帅比萌擦擦* 提交于 2019-12-05 17:10:25
I have two subclasses of Nan::ObjectWrap class Zyre: public Nan::ObjectWrap {...} class ZyreEvent: public Nan::ObjectWrap {...} How can I return a ZyreEvent javascript object from a method in Zyre ? I have the following method, in which I create a ZyreEvent : NAN_METHOD (Zyre::_recv) { Zyre *node = Nan::ObjectWrap::Unwrap <Zyre> (info.Holder ()); ZyreEvent *zyre_event = new ZyreEvent (node->self); info.GetReturnValue().Set(zyre_event->Wrap(info.This())); } But I can't Wrap the zyre_event because Wrap is a protected member. If I understand correctly, you want to return from (subclass of) Nan:

Error: Cannot find module 'nan'

蓝咒 提交于 2019-12-04 11:36:09
I'm working on native Node.js addon and following nan docs I included nan into binding.gyp like: "include_dirs" : [ "<!(node -e \"require('nan')\")" ] Also nan is in npm dependencies. But when I install the package inside the another node module node-gyp is failed with error > nnb@1.0.2 install /Users/Shopgate/sandbox/stress/node_modules/nnb > node-gyp rebuild module.js:338 throw err; ^ Error: Cannot find module 'nan' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Module.require (module.js:365:17) at require (module.js:384:17) at [eval]:1

node-ffi vs. node extension for accessing existing C++ functionality

眉间皱痕 提交于 2019-11-30 06:18:48
I've got some existing C++ code that does numerical processing within a stand-alone C++ application. I now want to use that code within a new node.js application. Researching how to access C++ code from node.js, two options come up: Write a node.js extension Use node-ffi node-ffi seems like a good option to access existing libraries , but am I right thinking if I use node-ffi I would have to write a C wrapper to make my C++ accessible? (This was the only way I could get a simple test case to work on Windows with Visual Studio). For my case where my source code is already in C++, not C, what

Node C++ Addon - How do I access a Typed Array (Float32Array) when it's beenn passed as an argument?

混江龙づ霸主 提交于 2019-11-29 11:37:34
I'd like to make use of the V8 Float32Array data structure. How can I initialise it? I'd also be interested in direct memory access to the data. How could that be done? Updated The best way now is to use the helper Nan::TypedArrayContents . assert(args[i]->IsFloat32Array()); Local<Float32Array> myarr = args[i].As<Float32Array>(); Nan::TypedArrayContents<float> dest(myarr); // Now use dest, e.g. (*dest)[0] There's a good example of this in node-canvas . Original Answer, which shows why the helper is useful The v8 API is changing rapidly right now so this depends on your version of node/io.js.

V8 Multithreaded function

南楼画角 提交于 2019-11-29 08:04:45
I'm writing a Node plugin and I'm having problems trying to call a V8 function object from a C++ worker thread. My plugin basically starts a C++ std::thread and enters a wait loop using WaitForSingleOject(), this is triggered by a different C++ app (An X-Plane plugin) writing to a bit of shared memory. I'm trying to get my Node plugin to wake up when the Windows shared event is signaled then call a JavaScript function that I've registered from the node app, which will in turn pass the data which originated in X-Plane back to Node and the web world. I've managed to work out how to register a