Thanks Ben.

I found another way to achieve my purpose. I defined getter and setter 
methods in JS so the C library can call these methods to get/set values.

It's not generic though because it works as long as the C library is called 
in the same v8 thread as the rest of the JS program. I posted another 
question related to this problem.

-- m1k3

On Monday, March 12, 2012 6:48:38 AM UTC-7, Ben Noordhuis wrote:
>
> On Mon, Mar 12, 2012 at 03:35, m1k3l <[email protected]> wrote:
> > Hi,
> >
> > I'd like to integrate a C library with node and there is a feature I 
> don't
> > seem to find a way to implement. Hopefully you can help.
> >
> > In this library, in C, one can pass a reference to a variable so it can 
> be
> > get/set by your code and get/set by the library, something
> > like: addVar(&aVar).
> > Later in your code, one can change the value. During the main loop, the
> > library can query this variable and do some processing with its value. It
> > may also set the value of this variable so that later in your code, you 
> can
> > use the new value.
> >
> > So my problems are:
> > 1- to pass a JS variable to this library
> > 2- to have this library set the value this JS variable
> >
> > Any idea, pointer, etc.. to do that?
>
> Look up v8::ObjectTemplate::SetNamedPropertyHandler(). It's basically
> the C++ counterpart to Object.defineProperty() and
> obj.__defineGetter__() / obj.__defineSetter__().
>

Reply via email to