vlad
unread,Nov 15, 2008, 3:26:15 PM11/15/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to v8-users
Hi,
I've been trying to add static variables getter/setter to function
templates, but have not found the proper way to do it.
I have successfully added instance getters/setters and instance
variable callbacks. Also, I was able to get the static function calls
working.
Let's assume class Foo;
// I have successfully installed C++ callbacks for objects in the
following statements:
var f = new Foo;
f.someVar = x;
var y = f.someVar;
f.bar();
Foo.staticCall();
But I have not been able to do this:
Foo.staticVariable = x;
var y = Foo.staticVariable;
I've been looking all day at v8.h,, process.cc, this mailing list, but
have not found the proper code snippets to make it happen.
This is an example of how I'm setting the above statements that work
-----------------------
// Create the Javascript:Camera class.
v8::Handle<v8::FunctionTemplate> cameraFunctionTpl =
v8::FunctionTemplate::New(jsi_Camera_construct);
v8::Handle<v8::ObjectTemplate> cameraInstanceTpl = cameraFunctionTpl-
>InstanceTemplate();
// Image = Camera.snapshot()
cameraFunctionTpl->Set(v8::String::New("snapshot"),
v8::FunctionTemplate::New(jsi_Camera_snapshot));
// Set the name of the class and a slot for the C++ class that will
hold it's data.
cameraFunctionTpl->SetClassName(v8::String::New("Camera"));
cameraInstanceTpl->SetInternalFieldCount(1); // create an internal
field for the C++ object
// $camera.target = node:Node; node:Node = $camera.target;
cameraFunctionTpl->PrototypeTemplate()->SetAccessor(v8::String::New
("target"), jsi_Camera_get_target, jsi_Camera_set_target);
// Add the Camera class template to the clobal object template.
global->Set(v8::String::New("Camera"), cameraFunctionTpl);
----------------------
Also, if does anyone know the difference, functionally, between:
cameraFunctionTpl->PrototypeTemplate()->SetAccessor(v8::String::New
("target"), jsi_Camera_get_target, jsi_Camera_set_target);
-- and --
cameraFunctionTpl->InstanceTemplate()->SetAccessor(v8::String::New
("target"), jsi_Camera_get_target, jsi_Camera_set_target);
Any help is appreciated.
Thanks,
Vlad