On Monday, 2 September 2013 09:41:42 UTC+1, Ben Noordhuis wrote: > > On Sun, Sep 1, 2013 at 11:40 PM, Kram Jordy <[email protected]<javascript:>> > 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()). > Thanks Ben. Just to let you know, that code won't compile under MinGW with gcc. It requires the template keyword ahead of the As() call, so it's getting pretty long and ugly... char* p = reinterpret_cast<char*>( info.Data().template As<External>()->Value() ); Cheers, Mark.
-- -- 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.
