Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Pass an int to a node.js addon
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ben Noordhuis  
View profile  
 More options Oct 26 2012, 10:16 am
From: Ben Noordhuis <i...@bnoordhuis.nl>
Date: Fri, 26 Oct 2012 16:16:44 +0200
Local: Fri, Oct 26 2012 10:16 am
Subject: Re: [nodejs] Pass an int to a node.js addon

On Fri, Oct 26, 2012 at 2:00 PM, NodeNinja <aeon6f...@gmail.com> wrote:

>> int length = args[0]->Int32Value();
>> if (length <= 0) {
>>   return ThrowException(Exception::Error(String::New("BAM")));
>> }
>> unsigned char* buffer = new unsigned char[length];

> Thanks for that info Ben,

> Further to that is there a way to pass and return array of pointers I have
> something like (unsigned int **)

Yep. Here is how you accept one:

  if (!args[0]->IsArray()) {
    return ThrowException(Exception::Error(String::New("BAM")));
  }
  Local<Array> array = Local<Array>::Cast(args[0]);
  uint32_t len = array->Length();
  Local<Value> first = array->Get(0);

And this is how you create one:

  Local<Array> array = Array::New(32); // 32=initial length, optional
  array->Set(0, String::New("first"));


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.