Ignore:
Timestamp:
Feb 13, 2011, 4:41:48 PM (9 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Reworked table handling
File:
1 edited

Legend:

Unmodified
Added
Removed
  • gaycko/trunk/src/js/glue.cpp

    r4748 r4768  
    1616using namespace v8;
    1717
     18int x = 42;
     19
     20
     21Handle<Value> XGetter(Local<String> property,
     22                      const AccessorInfo& info) {
     23    return Integer::New(x);
     24}
     25
     26void XSetter(Local<String> property, Local<Value> value,
     27             const AccessorInfo& info) {
     28    x = value->Int32Value();
     29}
     30
    1831char* testV8(void) {
    1932        // Create a stack-allocated handle scope.
    2033        HandleScope handle_scope;
     34   
     35        // Create a new context.
    2136
    22         // Create a new context.
    23         Persistent<Context> context = Context::New();
    24 
     37    Handle<ObjectTemplate> global_templ = ObjectTemplate::New();
     38    global_templ->SetAccessor(String::New("x"), XGetter, XSetter);
     39    Persistent<Context> context = Context::New(NULL, global_templ);
     40   
     41   
     42   
    2543        // Enter the created context for compiling and
    2644        // running the hello world script.
    2745        Context::Scope context_scope(context);
    28 
     46   
    2947        // Create a string containing the JavaScript source code.
    30         Handle<String> source = String::New("'Hello' + ', World!'");
    31 
     48        Handle<String> source = String::New("'Hello' + ', World!' + x");
     49   
    3250        // Compile the source code.
    3351        Handle<Script> script = Script::Compile(source);
    34 
     52   
    3553        // Run the script to get the result.
    3654        Handle<Value> result = script->Run();
    37 
     55   
    3856        // Dispose the persistent context.
    3957        context.Dispose();
    40 
     58   
    4159        // Convert the result to an ASCII string and print it.
    4260        String::AsciiValue ascii(result);
     61   
     62       
    4363        return strdup(*ascii);
    4464}
    45 
Note: See TracChangeset for help on using the changeset viewer.