Tag: node.js addon

在尝试检索时,通过nan传递数组返回未定义

我目前正在使用他们的c ++ / v8系统为NodeJS编写一个本地插件,并试图从Javascript写入一个数组到C ++,然后再检索它。 每当我尝试从数组中检索一个值并将其返回时,它将返回一个空数组 – 正如我最近潜入c ++中,我不确定这是我的误解指针/ c ++基础或NodeJS c ++交互。 我的档案如下: functions.cc #include "functions.h" #include <node.h> #include <nan.h> using namespace std; using namespace v8; NAN_METHOD(nothing) { } NAN_METHOD(aString) { info.GetReturnValue().Set(Nan::New("This is a thing.").ToLocalChecked()); } NAN_METHOD(aBoolean) { info.GetReturnValue().Set(false); } NAN_METHOD(aNumber) { info.GetReturnValue().Set(1.75); } NAN_METHOD(anObject) { v8::Local<v8::Object> obj = Nan::New<v8::Object>(); Nan::Set(obj, Nan::New("key").ToLocalChecked(), Nan::New("value").ToLocalChecked()); info.GetReturnValue().Set(obj); […]

Node.js 6 addon将Buffer.from()转换为const UInt8 *

嘿,我知道人们问过这个问题之前,无论出于何种原因,典型的答案不适合我。 基本上我有一个无符号的字节数组: var message = Buffer.from([ 0x27, 0x52, 0x00, 0x8E ]) myAddon.test(message); 在我的C ++模块中,我需要将ByteBuffer变成一个const UInt8 *数据结构。 我的代码目前是: #include <node.h> using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::Object; using v8::Value; using v8::Exception; void test(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = args.GetIsolate(); if (!args[0] ->IsObject()) { isolate -> ThrowException(Exception::TypeError( v8::String::NewFromUtf8(isolate, "All arguments must be string") )); return; […]

Nodejs Addon – 将正则expression式string传递给C ++

我想弄清楚如何在C ++中创build一个正则expression式。 我想将从JavaScript传递到C ++的string转换为正则expression式。 我有这个: std::regex re; if (!args[1]->IsString()) { Nan::ThrowTypeError("Second argument to 'replace-line' must be a string regular expression."); return; } else{ v8::String::Utf8Value regexin(args[1]->ToString()); re(*regexin); } 但是这个编译失败,出现这个错误: ../hello.cpp: In function 'void Method(const v8::FunctionCallbackInfo<v8::Value>&)': ../hello.cpp:50:16: error: no match for call to '(regex_t {aka re_pattern_buffer}) (char*)' re(*regexin); 任何人都知道我可以声明/创build一个regex给这个v8::String ?

使c ++插件asynchronous

我已经设法将dlibvideo跟踪器集成到我的节点应用程序中。 我现在的问题是让它不被阻塞。 任何帮助将不胜感激。 谢谢。 这是我的代码 #ifndef MYOBJECT_H #define MYOBJECT_H #include "ImageDetails.h" #include "opencv2/core/core_c.h" #include "../dlib/opencv/cv_image.h" #include "../dlib/image_processing.h" #include "../dlib/gui_widgets.h" #include "../dlib/image_io.h" #include "../dlib/dir_nav.h" #include "/home/pi/projects/lib/node-opencv-master/src/Matrix.h" #include "/home/pi/projects/lib/node-opencv-master/src/Contours.h" #include <nan.h> //#include <node_object_wrap.h> using namespace dlib; using namespace cv; using namespace std; class MyObject : public Nan::ObjectWrap { public: static void Init(v8::Local<v8::Object> exports); private: explicit MyObject(std::vector<ImageDetails> details, […]

错误:无法打开共享对象文件:没有这样的文件或目录

我正在为Node.js编写C ++插件 试图使用具有函数printHello声明的名为libSample.so的示例库: void printHello() { std::cout << "Hello World\n"; } 它工作得很好(编译使用node-gyp configure build和执行node ./ ) 当我试图使用另一个更复杂的库libCore.so。 开始执行时产生以下错误。 编译和configuration通过查找: module.js:597 return process.dlopen(module, path._makeLong(filename)); ^ Error: libPlayerCore.so: cannot open shared object file: No such file or directory at Error (native) at Object.Module._extensions..node (module.js:597:18) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at […]

如何使用v8原生插件将c ++数组传递给node.js

我实现了一个使用unsigned char(uint8_t)内存创build缓冲区的c ++插件模块,并将其传递给node.js. —- c ++ addon.cpp —- void get_frame_buffer(const FunctionCallbackInfo<Value>& args){ Isolate* isolate = helper.get_current_isolate(); if (!args[0]->IsUint32()&& !args[1]->IsUint32()) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Wrong arguments"))); return; } int width = args[0]->Uint32Value(); int height = args[1]->Uint32Value(); uint8_t* buf = new uint8_t[width * height * 4]; int length = width * height; memset(buf, 0, sizeof(buf)); for (int i […]

如何从NanAsyncWorker返回一个新的对象?

我正在做一个node.js / io.js本地插件,我需要从asynchronouscallback中创build一个新的本地对象。 使用南帮助者,我有这样的东西: 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 // ??? }; callback->Call(2, argv); } }; […]

在NodeJS插件中将args转换为double

我想将参数0转换为一个long,将其用于一个dll函数。 该函数被定义为long function(long) long __stdcall VBVMR_GetVoicemeeterVersion(long * pVersion); 而这个电话就像 void Voicemeeter_run(const FunctionCallbackInfo<Value>& args){ Isolate* isolate = Isolate::GetCurrent(); if (args.Length() < 1) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Run needs 1 argument"))); return; } if (!args[0]->IsNumber()) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Argument 1 must be a number"))); return; } long type = args[0]->NumberValue(); //long type = 2; long value = iVMR.VBVMR_RunVoicemeeter(type); […]

在void *中为Node.js插件检索和存储V8对象

我试图存储从JavaScript传递到Node.js插件在void * 。 我似乎无法得到这个编译; 用node-gyp构build会产生error: no matching function for call to 'Cast' 。 我试图做的长版本是编写一个运行Csound的Node.js插件。 Csound从鸟瞰的angular度出发,用C函数作为(通常)第一个参数,将一个指向不透明的Csound结构的指针。 这个结构包含一个void *到“ hostData ”,由一个托pipeCsound的程序设置的任意数据。 Csound所做的一些事情,比如发布消息,在这种情况下用callback函数指针进行修改。 我需要一个地方为Csound的每个实例存储callback,所以我想让某人从JavaScript设置hostData到一个对象,但是我也想把Csound实例的callback设置为这个hostData对象的隐藏属性 。 我认为代码将需要看起来像 #include "csound.h" #include <node.h> static void CsoundMessageCallback(CSOUND *Csound, int attributes, const char *format, va_list valist) { // Call the JavaScript function we stored in the hostData of Csound. } static void _wrap_csoundSetMessageCallback( […]

如何通过节点插件导出数组数据

我正在使用节点0.12.x,我想从c ++写的节点插件返回一些数组数据 Isolate* isolate = args.GetIsolate(); MyObject* obj = ObjectWrap::Unwrap<MyObject>(args.Holder()); obj->value_ += 1; args.GetReturnValue().Set(Number::New(isolate, obj->value_)); 这是返回Number数据的示例。