使用C++调用V8

文章来自:https://developers.google.com/v8/get_started


Hello World

下面的C++代码将调用V8的解释器,运行一段js代码。

#include 

using namespace v8;

int main(int argc, char* argv[]) {
  // Get the default Isolate created at startup.
  Isolate* isolate = Isolate::GetCurrent();

  // Create a stack-allocated handle scope.
  HandleScope handle_scope(isolate);

  // Create a new context.
  Handle context = Context::New(isolate);

  // Here's how you could create a Persistent handle to the context, if needed.
  Persistent persistent_context(isolate, context);
  
  // Enter the created context for compiling and
  // running the hello world script. 
  Context::Scope context_scope(context);

  // Create a string containing the JavaScript source code.
  Handle source = String::New("'Hello' + ', World!'");

  // Compile the source code.
  Handle
                    
                    

你可能感兴趣的:(使用C++调用V8)