node.js-addon

How to export array data through node addon

旧街凉风 提交于 2021-01-28 20:45:58
问题 I'm using node 0.12.x, I want to return some array data from node addon written by c++ Isolate* isolate = args.GetIsolate(); MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.Holder()); obj->value_ += 1; args.GetReturnValue().Set(Number::New(isolate, obj->value_)); This is a sample for returning Number data. 回答1: using namespace v8; Create an array: Local<Array> myArray = Array::New(isolate); You can then create objects with properties (or just integers) and push them into the array: for (int

Are Node.js buffers in C++ addon null terminated?

此生再无相见时 提交于 2021-01-28 13:31:09
问题 I am trying to create buffer in a .js file, and then passing that buffer to a c++ addon where I will call a Windows API. In the c++ addon I have: auto buf = node::Buffer::Data(args[0]); auto len = node::Buffer::Length(args[0]); Are there any guarantees that node::Buffers are null-terminated? Or does node::Buffer::Length have any other form of safety check to prevent an overrun? 回答1: No. Think of buffers as a minimal data structure containing length and memory; they are not raw memory like

Cannot load Node native addons with webpack

限于喜欢 提交于 2021-01-28 11:41:27
问题 Although I am using vue-cli in the example code to generate a webpack config, nothing is specific to vue. I create the example app like this: vue init webpack webpack_modules_example Generated webpack.base.conf : 'use strict' const path = require('path') const utils = require('./utils') const config = require('../config') const vueLoaderConfig = require('./vue-loader.conf') function resolve (dir) { return path.join(__dirname, '..', dir) } module.exports = { context: path.resolve(__dirname, '.

How do I use std::string in a C++ Addon for Node.js?

。_饼干妹妹 提交于 2021-01-27 19:04:58
问题 I'm trying to wrap C++ objects for use in javascript as per the node.js documentation here: https://nodejs.org/api/addons.html#addons_wrapping_c_objects The Addon would build without error, and work properly when my object "AnObject" only had numeric attributes i.e "int32_t age;". When I added the attribute "std::string name;" to AnObject, "node-gyp configure" worked, however "node-gyp build" gave the following error: Wills-MacBook-Pro:cppObjectWrapping willalley$ node-gyp build [...] In file

Understanding Node Addon API (N-API) HandleScope

痞子三分冷 提交于 2020-07-19 04:51:40
问题 I have difficulties to understand how to correctly use HandleScope and EscapableHandleScope. For example, from this Node example: MyObject::MyObject(const Napi::CallbackInfo& info) : Napi::ObjectWrap<MyObject>(info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); this->val_ = info[0].As<Napi::Number>().DoubleValue(); }; Why do we need to create a new HandleScope in this case? And from this other example: Napi::Object CreateObject(const Napi::CallbackInfo& info) { Napi::Env env =

Working with Node::Buffers in C++ Node Addons

谁都会走 提交于 2020-07-10 10:26:26
问题 I'm working on a Node addon that encrypts data using Windows DPAPI. I'm passing two Javascript Uint8Array to the C++ code using NAN. This is what the typescript interface looks like: export interface DpapiBindings{ protectData(dataToEncrypt: Uint8Array, optionalEntropy: Uint8Array, scope: string): Uint8Array } I'd like to then create a Node::Buffer in the C++ code: void ProtectData( Nan::NAN_METHOD_ARGS_TYPE info) { v8::Isolate* isolate = info.GetIsolate(); // auto buffer = node::Buffer::Data

Working with Node::Buffers in C++ Node Addons

允我心安 提交于 2020-07-10 10:26:20
问题 I'm working on a Node addon that encrypts data using Windows DPAPI. I'm passing two Javascript Uint8Array to the C++ code using NAN. This is what the typescript interface looks like: export interface DpapiBindings{ protectData(dataToEncrypt: Uint8Array, optionalEntropy: Uint8Array, scope: string): Uint8Array } I'd like to then create a Node::Buffer in the C++ code: void ProtectData( Nan::NAN_METHOD_ARGS_TYPE info) { v8::Isolate* isolate = info.GetIsolate(); // auto buffer = node::Buffer::Data

Angular: C++ Add On Errors for a virtual driver

ぃ、小莉子 提交于 2020-07-10 08:10:42
问题 I am trying to create a add for this driver https://github.com/robot9706/VirtualCameraDriver but I am getting below errors Please tell me if something specific is required and how to add it to Binding.gyp for DirectX based on https://groups.google.com/forum/#!topic/microsoft.public.win32.programmer.directx.video/XLaqyQt-krw DeviceEnumeration.obj : error LNK2001: unresolved external symbol IID_IBaseFilter [C:\Users\Downloads\blog-addons-example-master\build\testaddon.vcxproj] DeviceEnumeration

How to write to Uint8ClampedArray?

£可爱£侵袭症+ 提交于 2020-01-24 21:58:30
问题 I'm writing a node addon which accepts HTML canvas Image data, that's of type Uint8ClampedArray . I want to modify the the contents of this array without any extra copy. The best candidate I've found is the v8::Object::Set method (v8::Object being a class in Uint8ClampedArray's inheritance hierarchy) However that method requires a handle to v8::Context object as first argument. I don't know how to get that. I've searched through github repos and found code inside Webkit that directly casts

How to play ogg audio in electron with node addon?

别来无恙 提交于 2020-01-16 19:07:31
问题 I have an atom electron application that plays Ogg audios with HTML5 Audio API. I'm facing performance issues when running this program in very slow and old computers with Windows OS. I'm trying to fork a new process in electron and play the audios with a module or a node addon. But I'm not finding a module or a node addon to do this. Is there any module or node addon to play Ogg files and work with electron? 来源: https://stackoverflow.com/questions/57164605/how-to-play-ogg-audio-in-electron