I'm trying to use this method, but the object it returns is interpreted in the Javascript side as the class which is whold this variable, not as the type of variable it is. For instance, if I'm doing this:
alert(this.instanceOfSomeClass,someVar); the return value is assumed to be of type: SomeClass not of type 'someVar'. How can I change this so that the return value is seen as being of type 'someVar'? On Nov 25 2008, 12:21 pm, luiskarlos <[email protected]> wrote: > 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 fromhttp://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()); > > > > } --~--~---------~--~----~------------~-------~--~----~ v8-users mailing list [email protected] http://groups.google.com/group/v8-users -~----------~----~----~----~------~----~------~--~---
