1

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
  • I'd expand on this question if I were you. I don't even know what to ask for in further information. Commented Oct 16, 2015 at 4:24

1 Answer 1

3
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 i = 0; i < n; i++) {
    Local<Object> obj = Object::New(isolate);
    obj->Set(String::NewFromUtf8(isolate, "tag1"), "test");
    myArray->Set(i, obj);
 }

 args.GetReturnValue().Set(myArray);

If you're writing native code for node.js I highly recommend using nan: https://github.com/nodejs/nan

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.