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
-~----------~----~----~----~------~----~------~--~---