(I tried to send this a few hours ago, but the firewall of the building I was in apparently blocks SMTP)

It's possible, and generally pretty simple. Assume you have a function in C++ which would be called from _javascript_, and which should take a _javascript_ function as one of the arguments.

You'd do something somewhat like this:
//somewhere:
Persistent<Function> callback;

//in C++ function
if (args.Length() > 0)
{
callback = Persistent<Function>::New(Handle<Function>::Cast(args[0]));
}

//where you use the callback
if (!callback.IsEmpty())
{
Handle<Value> arguments[1];
arguments[0] = String::New("Hello, World!");
callback->Call(context->Global(), 1, arguments);
}


That's the gist, but it's nowhere near complete. Note: using a Persistent handle allows the function to remain in memory even if _javascript_ no longer references it, by maintaining a reference in C++.

For more information on Function::Call, look in v8.h (which basically contains all of the v8 documentation).

Alex

On Mar 3, 2009, at 8:48 AM, p1r0 wrote:


Hi!

I want to create a callback from C++ to _javascript_.
Like this, I want to be able to do something in C++ and let _javascript_
know when it's done by calling
a funcion.
Is there a way to do that?

Thanks!

--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to