Created
May 30, 2011 04:15
-
-
Save anaisbetts/998444 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
| // This is the main DLL file. | |
| #include "stdafx.h" | |
| #include "v8.h" | |
| #include <msclr\marshal.h> | |
| #include "V8Bridge.h" | |
| using namespace v8; | |
| using namespace msclr::interop; | |
| V8Bridge::V8ScriptCompiler::V8ScriptCompiler(System::String^ library_code) | |
| { | |
| HandleScope handleScope; | |
| Persistent<Context> context = Context::New(); | |
| marshal_context^ marshal = gcnew marshal_context(); | |
| Handle<String> src = String::New(marshal->marshal_as<const char*>(library_code)); | |
| Context::Scope context_scope(context); | |
| Handle<Script> script = Script::Compile(src); | |
| script->Run(); | |
| pFunc = &v8::Handle<v8::Function>::Cast(context->Global()->Get(v8::String::New("compilify"))); | |
| delete marshal; | |
| } | |
| V8Bridge::V8ScriptCompiler::~V8ScriptCompiler() | |
| { | |
| delete this->pFunc; | |
| } | |
| System::String^ V8Bridge::V8ScriptCompiler::Compile(System::String^ source) | |
| { | |
| HandleScope handleScope; | |
| marshal_context^ marshal = gcnew marshal_context(); | |
| v8::Handle<v8::Value> args[] = { String::New(marshal->marshal_as<const char*>(source)) }; | |
| v8::Local<v8::Value> result = *(*pFunc)->Call(*pFunc, 1, args); | |
| String::AsciiValue val(result); | |
| delete marshal; | |
| return marshal_as<System::String^>(*val); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment