Maybe you can try this:
// create the C++ Point to be wrapped
Point* p = new Point();
p->x = args[0]->Int32Value();
p->y = args[1]->Int32Value();
// make a persistant handle for the instance and make it
// weak so we get a callback when it is garbage collected
v8::Persistent<v8::Object> persistentPoint =
v8::Persistent<v8::Object>::New(args.Holder());
persistentPoint.MakeWeak(p, v8::WeakReferenceCallback
(Point_Destroy));
// set internal field to the C++ point
persistentPoint->SetInternalField(0, v8::External::New(p));
return persistentPoint;
I take this from http://home.cfl.rr.com/filedump/v8test.zip, I guess
it should work in the same way. :)..
On Nov 25, 10:11 am, vlad <[EMAIL PROTECTED]> wrote:
> Is there no one that knows about this?
>
> On Nov 21, 3:10 pm, vlad <[EMAIL PROTECTED]> wrote:
>
> > I have implemented 2 Javascript classes in C++, Camera and Point. I
> > can currently do this:
>
> > [code]
> > var camera = new Camera;
> > var point = new Point(x, y, z);
> > camera.position = point;
> > [/code]
>
> > I can get the values of point, inside Camera:position and set the
> > position of the camera fine.
> > My issue is that i don't know how to return a Point object when I do:
>
> > [code]
> > var point = camera.position;
> > [/code]
>
> > This is what I current have for setting and getting the
> > Camera::position variable, which is of type Point.
>
> > /**
> > * Get the position of camera.
> > *
> > * <javascript>
> > * usage: var vector = $camera.position;
> > * </javascript>
> > */
> > v8::Handle<v8::Value>
> > jsi_Camera_get_position(v8::Local<v8::String> property, const
> > v8::AccessorInfo& info)
> > {
> > JSCamera* camera = jsi_internal_Camera_unwrap_camera(info.Holder());
>
> > // Change the camera.
> > std::stringstream ss;
> > ss << "Camera.position (get)";
> > BBB::log(ss.str());
>
> > // How to return a Point?
>
> > return v8::True();
>
> > }
>
> > /**
> > * Set the position of camera.
> > *
> > * <javascript>
> > * usage: $camera.position = new Point(5.0, 5.0, 10.0);
> > * </javascript>
> > */
> > void
> > jsi_Camera_set_position(v8::Local<v8::String> property,
> > v8::Local<v8::Value> value, const v8::AccessorInfo& info)
> > {
> > JSCamera* camera = jsi_internal_Camera_unwrap_camera(info.Holder());
>
> > // ------------------------------------- //
> > // Make sure we have an object.
> > if (!value->IsObject()) {
> > std::stringstream ss;
> > ss << "Camera:position -- Argument must be of type [object
> > Point].";
> > BBB::log(ss.str());
> > return;
> > }
>
> > // Get the C++ class in this javascript object.
> > v8::Local<v8::Object> pointObj = value->ToObject();
> > v8::Local<v8::External> external = v8::Local<v8::External>::Cast
> > (pointObj->GetInternalField(0));
> > C4::Point3D* point = static_cast<C4::Point3D *>(external->Value());
> > // ------------------------------------- //
>
> > // Set the position of the node.
> > camera->SetNodePosition(*point);
>
> > // Change the camera.
> > std::stringstream ss;
> > ss << "Camera:position (set)";
> > BBB::log(ss.str());
>
> > }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/v8-users?hl=en
-~----------~----~----~----~------~----~------~--~---