As far as I can see you are just creating a JavaScript object and setting the six distinct properties "x", "y", "z", "0", "1" and "2". Changing any one of there properties will not affect the other. If you are trying to expose a C++ object to JavaScript take a look at the embedders guide at http://code.google.com/apis/v8/embed.html and look at the sections "Accessors" and "Interceptors".
Regards, Søren On Thu, Feb 18, 2010 at 15:01, choco <[email protected]> wrote: > Hi, I am working on a vector class. > I want the user to be able to do this: > > myvec.x = 3; > print(myvec.x); > > and also > > myvec[0] = 3; > print(myvec[0]); > > I tried this: > > Handle<Value> ConstructVec3(const v8::Arguments& args) > { > > // extract vec3 from argument > osg::Vec3& vec = > *static_cast<osg::Vec3*>(v8::External::Unwrap(args[0])); > > HandleScope handle_scope; > args[0]->ToNumber > Local<Value> x = Number::New(vec[0]); > Local<Value> y = Number::New(vec[1]); > Local<Value> z = Number::New(vec[2]); > args.This()->Set(String::New("x"), x); > args.This()->Set(Integer::New(0), x); > args.This()->Set(String::New("y"), y); > args.This()->Set(Integer::New(1), y); > args.This()->Set(String::New("z"), z); > args.This()->Set(Integer::New(2), z); > > return args.This(); > } > > But when I set myvec.x = 3 then myvec[0] still has the same value. > What can I do? > > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users > -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
