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

Received: by 10.66.81.200 with SMTP id c8mr6739106pay.1.1351233818801;
        Thu, 25 Oct 2012 23:43:38 -0700 (PDT)
X-BeenThere: nodejs@googlegroups.com
Received: by 10.68.212.6 with SMTP id ng6ls14676876pbc.4.gmail; Thu, 25 Oct
 2012 23:43:26 -0700 (PDT)
Received: by 10.68.231.7 with SMTP id tc7mr4956127pbc.1.1351233806514;
        Thu, 25 Oct 2012 23:43:26 -0700 (PDT)
Date: Thu, 25 Oct 2012 23:43:26 -0700 (PDT)
From: NodeNinja <aeon6f...@gmail.com>
To: nodejs@googlegroups.com
Message-Id: <1031894b-d6cc-43c9-bec0-3fcf75f53995@googlegroups.com>
Subject: Pass an int to a node.js addon
MIME-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_336_32023035.1351233806145"

------=_Part_336_32023035.1351233806145
Content-Type: multipart/alternative; 
	boundary="----=_Part_337_31621738.1351233806145"

------=_Part_337_31621738.1351233806145
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

My original c++  function had the following signature

unsigned char* random(int length);

To use this as an add-on I modified it to 

Handle<Value> random(const Arguments& args) {


if(args[0]->IsInt32()){

Local<Int32> length = args[0]->ToInt32();

// Now here I want to create an array like this "unsigned char* buffer = 
new unsigned char[length];"  using the length variable
// but it gives me an error saying length is undefined

//1.  how do I convert Local<Int32> to int ???
// 2. How to return the array from this function??


}

}

------=_Part_337_31621738.1351233806145
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

My original c++ &nbsp;function had the following signature<div><br></div><d=
iv><div>unsigned char*&nbsp;random(int length);</div></div><div><br></div><=
div>To use this as an&nbsp;add-on&nbsp;I&nbsp;modified&nbsp;it to&nbsp;<br>=
</div><div><br></div><div><div>Handle&lt;Value&gt; random(const Arguments&a=
mp; args) {</div></div><div><br></div><div><div><br></div><div><span class=
=3D"Apple-tab-span" style=3D"white-space:pre">=09</span>if(args[0]-&gt;IsIn=
t32()){</div><div><br></div><div><span class=3D"Apple-tab-span" style=3D"wh=
ite-space:pre">=09=09</span>Local&lt;Int32&gt; length =3D args[0]-&gt;ToInt=
32();</div><div><br></div><div>// Now here I want to create an array like t=
his "unsigned char* buffer =3D new unsigned char[length];" &nbsp;using the =
length variable</div><div>// but it gives me an error saying length is unde=
fined</div><div><br></div><div>//1. &nbsp;how do I convert Local&lt;Int32&g=
t; to int ???</div><div>// 2. How to return the array from this function??<=
/div><div><br></div><div><br></div><div><span class=3D"Apple-tab-span" styl=
e=3D"white-space:pre">=09</span>}</div></div><div><br></div><div>}</div>
------=_Part_337_31621738.1351233806145--

------=_Part_336_32023035.1351233806145--