On Sun, Sep 1, 2013 at 11:40 PM, Kram Jordy <[email protected]> wrote: > Hello, > Sorry if this is an obvious question, but I'm trying to pass a native c++ > data pointer through when setting up a function template for access within a > callback. > > So for example in the code below, if I wanted to pass 'buffer' through for > use within the LogCallback, what is the best way to achieve it? > > static char buffer[1024]; > Handle<ObjectTemplate> global = ObjectTemplate::New(); > global->Set(String::New("log"), FunctionTemplate::New(LogCallback)); > > Looking at FunctionTemplate I see this constructor is available... > > static Local<FunctionTemplate> New( > FunctionCallback callback = 0, > Handle<Value> data = Handle<Value>(), > Handle<Signature> signature = Handle<Signature>(), > int length = 0); > > So do I have to wrap this buffer pointer into a Handle<Value>() somehow and > supply it as the 2nd data argument? > > Then I could get the value back using the Data() method of the AccessorInfo? > > class PropertyCallbackInfo { > public: > V8_INLINE(Local<Value> Data() const); > V8_INLINE(Local<Object> This() const); > V8_INLINE(Local<Object> Holder() const); > Or perhaps I'm on the wrong track...? > > Thanks, > Mark.
You're on the right track. :-) You can wrap the buffer with External::New(), then retrieve it later with static_cast<char*>(info.Data().As<External>()->Value()). -- -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
