Created
February 20, 2014 02:13
-
-
Save diogo-karma/2f89b0c6acdae2bc649c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <v8.h> | |
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 = Context::New(isolate); | |
// Enter the context for compiling and running the hello world script. | |
Context::Scope context_scope(context); | |
// Create a string containing the JavaScript source code. | |
Handle<String> source = String::NewFromUtf8(isolate, "'Hello' + ', World!'"); | |
// Compile the source code. | |
Handle<Script> script = Script::Compile(source); | |
// Run the script to get the result. | |
Handle<Value> result = script->Run(); | |
// Convert the result to an UTF8 string and print it. | |
String::Utf8Value utf8(result); | |
printf("%s\n", *utf8); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment