#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> source = String::New("var str = 1 + 2");
Handle<Script> script = Script::Compile(source);
script->Run();
Handle<String> data = String::New("str");
Handle<Value> str = context->Global()->Get(data);
String::AsciiValue ascii(str);
printf("%s\n", *ascii);
return 0;
}
留意context->Global()->Get(data);的用法,和data參數的類型是Handle<String>
v8學習---獲取js變量的值
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.