我正在使用NAN在 node.js 中包含一个 c++ 库。我了解如何在两者之间来回传递数字和字符串,但我不明白如何传递数组。我想做的是这样的:
index.js
var test = require('bindings')('test');
var buffer = [0,0,0,0,0,0.1,0,0,0,0,-0.1];
test.encode(buffer, buffer.length);
测试.cc
var encoder = new Encoder();
NAN_METHOD(Encode){
//the next line is incorrect, I want to take the buffer array and pass it as a pointer to the encodeBuffer() function
Local<Number> buffer = args[0].As<Number>();
//get the integer value of the second argument
Local<Number> buffer_length = args[1].As<Number>();
int bl_int = buffer_length->IntegerValue();
//call function
encoder.encodeBuffer(buffer, bl_int);
}
void Init(Handle<Object> exports) {
exports->Set(NanNew("encode"), NanNew<FunctionTemplate>(Encode)->GetFunction());
}
声明了我想从 c++ 库中使用的实际方法:
void encodeBuffer(float *buffer, size_t l);
我尝试查看文档,但他们没有说任何关于指针和数组的内容。我错过了什么吗?