source: gaycko/trunk/src/js/glue.cpp @ 4725

Last change on this file since 4725 was 4725, checked in by Jean-Yves Lamoureux, 11 years ago
  • Added C++ stuff on top of gaycko.cpp (which must be compiled with g++)
File size: 819 bytes
Line 
1#include <v8.h>
2#include "js/glue.h"
3
4using namespace v8;
5
6int testV8(void) {
7        // Create a stack-allocated handle scope.
8        HandleScope handle_scope;
9
10        // Create a new context.
11        Persistent<Context> context = Context::New();
12
13        // Enter the created context for compiling and
14        // running the hello world script.
15        Context::Scope context_scope(context);
16
17        // Create a string containing the JavaScript source code.
18        Handle<String> source = String::New("'Hello' + ', World!'");
19
20        // Compile the source code.
21        Handle<Script> script = Script::Compile(source);
22
23        // Run the script to get the result.
24        Handle<Value> result = script->Run();
25
26        // Dispose the persistent context.
27        context.Dispose();
28
29        // Convert the result to an ASCII string and print it.
30        String::AsciiValue ascii(result);
31        printf("'%s'\n", *ascii);
32        return 0;
33
34}
35
Note: See TracBrowser for help on using the repository browser.