参考:http://iammr.7.blog.163.com/blog/static/49102699201201565822189/
获取全局对象成员
#include<v8.h>
using namespace v8;
int main()
{
Isolate* isolate = Isolate::GetCurrent();
HandleScope handleScope(isolate);
Handle<Context> context = Context::New(isolate);
Context::Scope context_scope(context);
Handle<String> string = String::New("function Point() { this.x = 3; this.y = 4; }; var p = new Point(); ");
Handle<Script> script = Script::Compile(string);
script->Run();
Handle<String> str = String::New("p");
Handle<Value> data_p = context->Global()->Get(str);
Handle<Object> p = Handle<Object>::Cast(data_p);
Handle<Value> x = String::New("x");
Handle<Value> value = p->Get(x);
String::AsciiValue ascii(value);
printf("%s\n", *ascii);
return 0;
}
注意其中:
Handle<Object> p = Handle<Object>::Cast(data_p);