Hi corey !
I've tried that :
Handle<Value> oVal = _context->Global ()->Get (String::New ("object"));
if (oVal->IsObject ())
{
Handle<Object> o = Handle<Object>::Cast (oVal);
Handle<Object> oProt = Handle<Object>::Cast (o->GetPrototype ());
oProt->Set (String::New("ToJSON"), FunctionTemplate::New(::ToJSON),
DontEnum);
}
But I got this error when I compile :
1>c:\msdev6\myprojects\jss\jss\..\V8\include\v8.h(198) : error C2440: '=' :
cannot convert from 'v8::FunctionTemplate *' to 'v8::Value *'
1> Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
1> .\JSS.cpp(64) : see reference to function template instantiation
'v8::Handle<T>::Handle<v8::FunctionTemplate>(v8::Handle<v8::FunctionTemplate>)'
being compiled
1> with
1> [
1> T=v8::Value
1> ]
Best regards,
Florent Steiner
On Mon, Oct 13, 2008 at 4:54 PM, corey <[EMAIL PROTECTED]> wrote:
>
> If you have a handle to an object you can add a c++ function to the
> prototype like this:
>
> object->GetPrototype()->Set(
> String::New("Name_Of_Function"),
> FunctionTemplate::New(pointer_to_c++_function));
>
> If you want to add the function with the implementation being handled
> in javascript then you could do something along these lines:
>
> Script::Compile(String::New("Object.prototype.myFunc = function ()
> { ... }"))->Run();
>
>
>
> Corey
>
> On Oct 12, 5:35 pm, Florent Steiner <[EMAIL PROTECTED]> wrote:
> > Wow, I'm totaly lost, there.
> >
> > I would like to extend the Object prototype like this :
> >
> > Object.prototype.myFunc = function () {
> > ...
> >
> > }
> >
> > But I don't know how to do so in C++ :(
> >
> > Could somebody help me ?
> >
> > Regards,
> > Florent Steiner
> >
>
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---