So I figured out what I wanted to have done. I believe this method
( at least for my purposes ) is a bit more manageable for small class
structures.

This is defined in a JS file:

function MyClass( )
{
}
MyClass.prototype=
{
    myField1 : 0,
    myField2 : 0,

    myFunction : function( )
    {
        ....do stuff
    }
}

Then in C++ code:

v8::Handle< v8::Value > val = Context->Global()->Get(v8::String::New
("MyClass"));
if(val->IsFunction())
{
    v8::Handle< v8::Function > f = v8::Handle< v8::Function >::Cast
( val );
    v8::Local< v8::Object > o = f->NewInstance();
    v8::Local< v8::Value > f1 = o->Get(v8::String::New("myField1"));
    if(f1->IsNumber())
        printf("FOUND FIELD");
    o->Set(v8::String::New("myField1"),v8::Number::New(100));
}

So with this I can handle these objects coming into C++ and also
return these objects back into script without having manage any
special structures or setup in C++;


If any one sees any issues with this method let me know what you
think.

On Apr 2, 10:50 am, MJ <[email protected]> wrote:
> I already wrap all kinds of classes to V8, but maybe I phrased my
> question wrong. What I want to do is create the definition in script
> so I do not have to manage C++ objects for classes that are not bigger
> than a couple utility methods, and let V8 manage the objects. Like
> with the Point example I think it is a bit of overkill to wrap an
> object that has 2 fields and maybe one function. I already do this for
> a couple of utility classes I have that are written in JS, but I was
> seeing if there was a way to get at the function prototype of the
> class from JS to be able to create an instance of the function and
> push it to script.
>
> On Apr 2, 10:44 am, Alex Iskander <[email protected]> wrote:
>
> > The way you do it is by making the constructor a C++ function. A bit  
> > of reference on how to do this is in the following places:
> > The v8 embedder's guide
>
> > The example files in the v8 source tree
>
> > My own article which covers some of the techniques to wrap v8 
> > objects:http://create.tpsitulsa.com/blog/2009/01/29/v8-objects/
>
> > Also, as far as I know there is no way to intercept operators.
>
> > Hope that helps,
>
> > Alex
>
> > Sent from Alex's iPhone
>
> > On Apr 2, 2009, at 10:26 AM, MJ <[email protected]> wrote:
>
> > > This is kind of a 2 part question.
>
> > > 1) Are you able to get a class created in script in C++ and create an
> > > object of that type in C++ and then push it back to script? Like can
> > > you get the function from the engine and get the instance template
> > > from it and create a new instance.
>
> > > function MyClass()
> > > {
> > > }
>
> > > And then in C++ get MyClass and create an instance of it?
>
> > > 2) Also, is it possible to override or intercept operators?
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to