hey thanks a lot!
On Sep 15, 5:30 pm, [EMAIL PROTECTED] wrote:
> It's really quite easy,
>
> As a starting point you can look at the code in the process.cc example
>
> Lines 178-192 locate the callback function by name and stores it a
> persistent handle named 'process_' - the script must have been
> compiled before searching for the function by name.
>
> // The script compiled and ran correctly. Now we fetch out the
> // Process function from the global object.
> Handle<String> process_name = String::New("Process");
> Handle<Value> process_val = context->Global()->Get(process_name);
>
> // If there is no Process function, or if it is not a function,
> // bail out
> if (!process_val->IsFunction()) return false;
>
> // It is a function; cast it to a Function
> Handle<Function> process_fun = Handle<Function>::Cast(process_val);
>
> // Store the function in a Persistent handle, since we also want
> // that to remain after this call returns
> process_ = Persistent<Function>::New(process_fun);
>
> Then lines 259 - 263 set up some args and call the function
>
> // Invoke the process function, giving the global object as 'this'
> // and one argument, the request.
> const int argc = 1;
> Handle<Value> argv[argc] = { request_obj };
> Handle<Value> result = process_->Call(context_->Global(), argc,
> argv);
>
> All of this assumes you are calling the callback function on the same
> thread that created the context ( and that the context handle doesn't
> go out of scope or is stored in a persist handle as in lines 161 - 164
> of process.cc
>
> // Store the context in the processor object in a persistent handle,
> // since we want the reference to remain after we return from this
> // method.
> context_ = Persistent<Context>::New(context);
>
> Cheers, Paul.
>
> On Sep 15, 2:54 pm, rajika <[EMAIL PROTECTED]> wrote:
>
> > hi,
> > Can you share the code that made this possible, I want to do the same
> > thing, i.e. to call aJavascriptmethod (with an argument) withinC++
> > and get the result. Thanks in advance.
>
> > On Sep 6, 5:10 am, [EMAIL PROTECTED] wrote:
>
> > > Thanks Fenq, that's exactly what I needed.
>
> > > Cheers, Paul.
>
> > > On Sep 5, 1:57 pm, Feng Qian <[EMAIL PROTECTED]> wrote:
>
> > > > Do you mean 'callJavaScriptmethod fromC++'?
>
> > > > If you, you can do
>
> > > > Handle<Value> func = Handle<Function>::Cast(obj->Get(func_name));
> > > > Handle<Value> result = func->Call(obj, ...);
>
> > > > Function is just a JSObject, whencallingthe function, you pass obj
> > > > as the receiver
> > > > to Function::Call.
>
> > > > Cheers,
> > > > Feng
>
> > > > On Thu, Sep 4, 2008 at 3:07 PM, <[EMAIL PROTECTED]> wrote:
>
> > > > > Just to clarify, I have the v8 object handle, I need to call the
> > > > >javascriptmethod by name
>
> > > > > On Sep 5, 8:04 am, [EMAIL PROTECTED] wrote:
> > > > >> I have been using SpiderMonkey, however as aC++veteran I am far more
> > > > >> comfortable with embedded programming in v8.
>
> > > > >> I have a need to call fromC++a method on ajavascriptobject handle
> > > > >> by name, as yet I have been unable to determine a way to do this by
> > > > >> inspecting the v8 code.
>
> > > > >> Does anybody know if there is a way I can do this ?
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---