Advertisement
Guest User

example_v8.cpp

a guest
Feb 28th, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. int main(int argc, char* argv[])
  2. {
  3.     string file = removeExe(argv[0]);
  4.     file.append("init.js");
  5.     cout << file << endl;
  6.    
  7.     Isolate* isolate = Isolate::GetCurrent();
  8.     HandleScope handle_scope(isolate);
  9.  
  10.     // ----------------------------------------------------------
  11.  
  12.     // Global object
  13.     Handle<ObjectTemplate> global = ObjectTemplate::New(isolate);
  14.    
  15.     global->Set(String::NewFromUtf8(isolate, "print"), FunctionTemplate::New(isolate, Print));
  16.     global->Set(String::NewFromUtf8(isolate, "exit"), FunctionTemplate::New(isolate, Exit));
  17.     global->Set(String::NewFromUtf8(isolate, "waitpress"), FunctionTemplate::New(isolate, Getch));
  18.     global->Set(String::NewFromUtf8(isolate, "myname"), FunctionTemplate::New(isolate, MyName));
  19.     global->Set(String::NewFromUtf8(isolate, "clearscreen"), FunctionTemplate::New(isolate, ClearScreen));
  20.     global->Set(String::NewFromUtf8(isolate, "tochar"), FunctionTemplate::New(isolate, ToChar));
  21.  
  22.    
  23.     // ----------------------------------------------------------
  24.  
  25.     Handle<Context> context = Context::New(isolate, NULL, global);
  26.  
  27.     Persistent<Context> persistent_context(isolate, context);
  28.  
  29.     Context::Scope context_scope(context);
  30.  
  31.     Handle<String> source_obj = ReadFile(isolate, file);
  32.  
  33.     Handle<Script> script_obj = Script::Compile(source_obj);
  34.  
  35.     Handle<Value> local_result = script_obj->Run();
  36.    
  37.     String::Utf8Value utf8(local_result);
  38.     printf("Result: %s\n", utf8);
  39.  
  40.     _getch();
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement