#include <v8.h>
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "v8_base.ia32.lib")
#pragma comment(lib, "v8_snapshot.lib")
#pragma comment(lib, "icui18n.lib")
#pragma comment(lib, "icuuc.lib")
using namespace v8;
int main(int argc, char *argv[])
{
v8::V8::InitializeICU();
//v8::Isolate* isolate = v8::Isolate::New();v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
v8::Isolate* isolate = v8::Isolate::GetCurrent();
{
// 創建一個句柄作用域 ( 在棧上 )
HandleScope handle_scope(isolate);
// 創建一個新的上下文對象
v8::Handle<v8::Context> context = Context::New(isolate);
if (context.IsEmpty())
{
fprintf(stderr, "Error creating context\n");
return 1;
}
context->Enter();
// 創建一個字符串對象,字符串對象被 JS 引擎
// 求值後,結果為'Hello, World!2013'
Handle<String> source = String::New("'hello,World!'+(2012+1)");
// 編譯字符串對象為腳本對象
Handle<Script> script = Script::Compile(source);
// 執行腳本,獲取結果
Handle <Value> result = script->Run();
// 轉換結果為字符串
String::AsciiValue ascii(result);
printf("%s\n", *ascii);
context->Exit();
}
v8::V8::Dispose();
return 0;
}