Hi all,

To export a global object to JS is ok. But how to new an object in JS and use 
it ? The object is a C++ object.

I think it should be wrapped first and then give it external position and 
export to JS context. But how to do it in details ?

below is my code , not finished yet.

Anyone who have known this would give big help ! thanks a lot !

=====================================================================

class TestObj{public:
    int x;public:
    TestObj();
    ~TestObj();

    void doAction(const v8::FunctionCallbackInfo<v8::Value>& args){
        printf("do action called\n");
    }
    Handle<Value> getOtherObj(const v8::FunctionCallbackInfo<v8::Value>& 
args);};
int main(int argc, _TCHAR* argv[]){
    Isolate* isolate = Isolate::GetCurrent();
    HandleScope handle_scope(isolate);
    Local<Context> context = Context::New(isolate);
    Context::Scope context_scope(context);

    // ====================================================================
    Handle<String> source = String::NewFromUtf8(isolate,
    "var obj = new TestObj();"
    "obj.doAction();"
    );

    // Compile the source code..
    Handle<Script> script = Script::Compile(source);
    Handle<Value> result = script->Run();
    String::Utf8Value utf8(result);
    printf("%s\n", *utf8);

    // end -----------------------------------------------------------------
    system("pause");
    return 0;}

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to