I want expand C++ Class in V8.
c++:
  class A{
  public:
     print();
  }
  class B{
  public:
     static A* pA;
  }

Now, I can  write in Javascript like this:
  var a = new A();
  a.print();
Next I want do like this:
  B.pA.print();

problem:
   How can I return a calss A type object I registered to global in pA's 
AccessorGetter function, which can call  print()


*main code for expand class A:*
*
*
HandleScope handle_scope;
Handle<FunctionTemplate> ft = FunctionTemplate::New(AWrapper::Constructor);
ft->SetClassName(String::New("A"));
Handle<ObjectTemplate> ot = ft->InstanceTemplate();
ot->SetInternalFieldCount(1); 
Handle<ObjectTemplate> pt = ft->PrototypeTemplate();
pt->Set("print", FunctionTemplate::New(A::print));
global->Set(String::New("A"), ft->GetFunction());

*Handle<Value> AWrapper::Constructor(const Arguments & args)*
{
if (!args.IsConstructCall()) 
{ 
return v8::ThrowException(v8::Exception::Error(v8::String::New("Invalid 
call format. 

Please use the 'new' operator."))); 
}

A *a = new A();
args.This()->SetPointerInInternalField(0,a);
return args.This();
}

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to