It doesn't work directly. However, all v8 callbacks support setting
some "data" that will be passed back. You can use the instance for
that.

For example:
  void SetInstanceCallAsFunctionHandler(InvocationCallback callback,
Handle<Value> data);

If you have an instance Foo *foo on which you'd like to have #bar
called, you can define:

Foo* foo;
functionTemplate->SetInstanceCallAsFunctionHandler(unwrapFooAndCallBar,
External::New(foo));

Handle<Value> unwrapFooAndCallBar(const Arguments& args) {
  Foo* foo = static_cast<Foo>(Handle<External>::Cast(args.Data())->Value());
  foo->bar(args);
}

It's a little tedious but works like a charm. Some template magic
might even make this easier.

Matthias


On Sat, Oct 10, 2009 at 5:53 PM, Scott Sibley <[email protected]> wrote:
> Well, after some research I see it's not possible. Unless someone knows a
> way. I don't see it.
>
> On Sat, Oct 10, 2009 at 2:00 AM, Starlon <[email protected]> wrote:
>>
>> I found out tonight that I can't use a class method as the function
>> for a FunctionTemplate. Why's this the case? Is there a way to make
>> this work so I can link a class/object's method to a javascript
>> function?
>
> >
>

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

Reply via email to