Commits

Anonymous committed 3473c7f

  • Participants

Comments (0)

Files changed (11)

+
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PyV8", "src\PyV8.vcproj", "{4A863005-2619-4CD1-843E-73E23AF6E8F6}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Release|Win32 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{4A863005-2619-4CD1-843E-73E23AF6E8F6}.Debug|Win32.ActiveCfg = Debug|Win32
+		{4A863005-2619-4CD1-843E-73E23AF6E8F6}.Debug|Win32.Build.0 = Debug|Win32
+		{4A863005-2619-4CD1-843E-73E23AF6E8F6}.Release|Win32.ActiveCfg = Release|Win32
+		{4A863005-2619-4CD1-843E-73E23AF6E8F6}.Release|Win32.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

File PyV8.suo

Binary file added.

File src/Engine.cpp

+#include "StdAfx.h"
+#include "Engine.h"
+
+CEngine::CEngine(py::object global) 
+{
+  v8::HandleScope handle_scope;
+
+  m_context = v8::Context::New(NULL, v8::ObjectTemplate::New());
+
+  v8::Context::Scope context_scope(m_context);
+  
+  m_wrapper.Attach(*m_context);
+
+  m_context->Global()->Set(v8::String::New("__proto__"), m_wrapper.Wrap(global));  
+}
+
+void CEngine::Expose(void)
+{
+  v8::V8::Initialize();
+  v8::V8::SetFatalErrorHandler(ReportFatalError);
+  v8::V8::AddMessageListener(ReportMessage);
+
+  py::register_exception_translator<CEngineException>(CPythonException::translator);
+  py::register_exception_translator<CWrapperException>(CPythonException::translator);
+
+  py::class_<CEngine, boost::noncopyable>("Engine", py::no_init)
+    .def(py::init< py::optional<py::object> >(py::args("global")))
+
+    .add_static_property("version", &CEngine::GetVersion)
+
+    .def("compile", &CEngine::Compile)
+    .def("eval", &CEngine::Execute)
+    ;
+}
+
+void CEngine::ReportFatalError(const char* location, const char* message)
+{
+  std::ostringstream oss;
+
+  oss << "<" << location << "> " << message;
+
+  throw CEngineException(oss.str());
+}
+
+void CEngine::ReportMessage(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data)
+{
+  UNREFERENCED_PARAMETER(data);
+
+  v8::String::AsciiValue filename(message->GetScriptResourceName());
+  int lineno = message->GetLineNumber();
+  v8::String::AsciiValue sourceline(message->GetSourceLine());
+
+  std::ostringstream oss;
+
+  oss << *filename << ":" << lineno << " -> " << *sourceline;
+
+  ::PyErr_SetString(::PyExc_UserWarning, oss.str().c_str());
+}
+
+boost::shared_ptr<CScript> CEngine::Compile(const std::string& src)
+{
+  v8::HandleScope handle_scope;
+
+  v8::Context::Scope context_scope(m_context);
+
+  v8::TryCatch try_catch;
+
+  v8::Handle<v8::String> source = v8::String::New(src.c_str());
+  v8::Handle<v8::Value> name = v8::Undefined();
+
+  v8::Handle<v8::Script> script = v8::Script::Compile(source, name);
+
+  if (script.IsEmpty()) throw CEngineException(try_catch);
+
+  return boost::shared_ptr<CScript>(new CScript(*this, src, v8::Persistent<v8::Script>::New(script)));
+}
+
+py::object CEngine::Execute(const std::string& src)
+{
+  return Compile(src)->Run();
+}
+
+py::object CEngine::ExecuteScript(v8::Persistent<v8::Script>& script)
+{    
+  v8::HandleScope handle_scope;
+
+  v8::Context::Scope context_scope(m_context);
+
+  v8::TryCatch try_catch;
+
+  v8::Handle<v8::Value> result = script->Run();
+
+  if (result.IsEmpty()) throw CEngineException(try_catch);
+
+  if (result->IsUndefined()) return py::object();
+
+  return py::str(std::string(*v8::String::AsciiValue(result)));
+}
+
+void CScript::Expose(void)
+{
+  py::objects::class_value_wrapper<boost::shared_ptr<CScript>, 
+    py::objects::make_ptr_instance<CScript, 
+    py::objects::pointer_holder<boost::shared_ptr<CScript>,CScript> > >();
+
+  py::class_<CScript, boost::noncopyable>("Script", py::no_init)
+    .add_property("source", &CScript::GetSource)
+
+    .def("run", &CScript::Run)
+    ;
+}

File src/Engine.h

+#pragma once
+
+#include <stdexcept>
+#include <string>
+
+#include <boost/shared_ptr.hpp>
+
+#include "Wrapper.h"
+
+class CEngineException : public CPythonException
+{
+  const std::string generate(v8::TryCatch& try_catch)
+  {
+    v8::String::AsciiValue exception(try_catch.Exception());
+
+    return *exception;
+  }
+public:
+  CEngineException(v8::TryCatch& try_catch) 
+    : CPythonException(generate(try_catch))
+  {
+  }
+
+  CEngineException(const std::string& msg)
+    : CPythonException(msg)
+  {
+  }
+};
+
+class CScript;
+
+class CEngine
+{  
+  v8::Persistent<v8::Context> m_context;
+  CPythonWrapper m_wrapper;
+protected:
+  static void ReportFatalError(const char* location, const char* message);
+  static void ReportMessage(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data);  
+public:
+  CEngine(py::object global = py::object());
+
+  ~CEngine()
+  {
+    m_wrapper.Detach();
+    m_context.Dispose();
+  }
+
+  boost::shared_ptr<CScript> Compile(const std::string& src);
+  py::object Execute(const std::string& src);
+
+  void RaiseError(v8::TryCatch& try_catch);
+public:
+  static void Expose(void);
+
+  static const std::string GetVersion(void) { return v8::V8::GetVersion(); }
+
+  v8::Persistent<v8::Context>& GetContext(void) { return m_context; }
+
+  py::object ExecuteScript(v8::Persistent<v8::Script>& m_script);
+};
+
+class CScript
+{
+  CEngine& m_engine;
+  const std::string m_source;
+
+  v8::Persistent<v8::Script> m_script;  
+public:
+  CScript(CEngine& engine, const std::string& source, const v8::Persistent<v8::Script>& script) 
+    : m_engine(engine), m_source(source), m_script(script)
+  {
+
+  }
+  ~CScript()
+  {
+    m_script.Dispose();
+  }
+
+  static void Expose(void);
+
+  const std::string GetSource(void) const { return m_source; }
+
+  py::object Run(void) { return m_engine.ExecuteScript(m_script); }
+};

File src/PyV8.cpp

+// PyV8.cpp : Defines the entry point for the DLL application.
+//
+
+#include "stdafx.h"
+
+#include <sstream>
+
+#include "Engine.h"
+
+BOOST_PYTHON_MODULE(_PyV8)
+{
+  CEngine::Expose();
+  CScript::Expose();
+}
+#!/usr/bin/env python
+import _PyV8
+
+Engine = _PyV8.Engine
+
+import unittest
+
+class TestEngine(unittest.TestCase):
+    def testClassProperties(self):
+        self.assertEquals("1.0.1", Engine.version)
+        
+    def testCompile(self):
+        engine = Engine()
+        
+        try:
+            s = engine.compile("1+2")
+            
+            self.assertEquals("1+2", s.source)
+            self.assertEquals("3", s.run())
+        finally:
+            del engine
+            
+    def testExec(self):
+        engine = Engine()
+        
+        try:
+            self.assertEquals("3", engine.eval("1+2"))
+        finally:
+            del engine
+            
+    def testGlobal(self):
+        class Global(object):
+            version = "1.0"
+            
+        context = Global()
+        engine = Engine(context)
+        
+        try:
+            self.assertEquals(Global.version, engine.eval("version"))
+        finally:
+            del engine
+
+if __name__ == '__main__':
+    unittest.main()

File src/PyV8.vcproj

+<?xml version="1.0" encoding="gb2312"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="8.00"
+	Name="PyV8"
+	ProjectGUID="{4A863005-2619-4CD1-843E-73E23AF6E8F6}"
+	RootNamespace="PyV8"
+	Keyword="Win32Proj"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(SolutionDir)\bin\$(ConfigurationName)"
+			IntermediateDirectory="$(SolutionDir)\objs\$(ProjectName)\$(ConfigurationName)"
+			ConfigurationType="2"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="..\lib\v8\inc;..\lib\boost\inc;..\lib\python\inc"
+				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;BOOST_PYTHON_STATIC_LIB"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="1"
+				UsePrecompiledHeader="2"
+				WarningLevel="4"
+				Detect64BitPortabilityProblems="false"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="Winmm.lib"
+				OutputFile="$(OutDir)\_$(ProjectName).pyd"
+				LinkIncremental="2"
+				AdditionalLibraryDirectories="..\lib\v8\lib\debug;..\lib\boost\lib;..\lib\python\lib"
+				IgnoreDefaultLibraryNames=""
+				GenerateDebugInformation="true"
+				SubSystem="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+				CommandLine="copy PyV8.py $(OutDir)&#x0D;&#x0A;$(OutDir)\PyV8.py&#x0D;&#x0A;"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(SolutionDir)\bin\$(ConfigurationName)"
+			IntermediateDirectory="$(SolutionDir)\objs\$(ProjectName)\$(ConfigurationName)"
+			ConfigurationType="2"
+			CharacterSet="1"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories="..\lib\v8\inc;..\lib\boost\inc;..\lib\python\inc"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;BOOST_PYTHON_STATIC_LIB"
+				RuntimeLibrary="0"
+				EnableFunctionLevelLinking="true"
+				UsePrecompiledHeader="2"
+				WarningLevel="4"
+				Detect64BitPortabilityProblems="false"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="Winmm.lib"
+				OutputFile="$(OutDir)\_$(ProjectName).pyd"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="..\lib\v8\lib\debug;..\lib\boost\lib;..\lib\python\lib"
+				GenerateDebugInformation="true"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCWebDeploymentTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+			>
+			<File
+				RelativePath=".\Engine.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\PyV8.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\stdafx.cpp"
+				>
+				<FileConfiguration
+					Name="Debug|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"
+					/>
+				</FileConfiguration>
+				<FileConfiguration
+					Name="Release|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"
+					/>
+				</FileConfiguration>
+			</File>
+			<File
+				RelativePath=".\Wrapper.cpp"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+			>
+			<File
+				RelativePath=".\Engine.h"
+				>
+			</File>
+			<File
+				RelativePath=".\stdafx.h"
+				>
+			</File>
+			<File
+				RelativePath=".\Wrapper.h"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+			>
+		</Filter>
+		<Filter
+			Name="Unit Tests"
+			>
+			<File
+				RelativePath=".\PyV8.py"
+				DeploymentContent="true"
+				>
+			</File>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>

File src/Wrapper.cpp

+#include "StdAfx.h"
+#include "Wrapper.h"
+
+v8::Handle<v8::Value> CPythonWrapper::Getter(
+  v8::Local<v8::String> prop, const v8::AccessorInfo& info)
+{
+  v8::HandleScope handle_scope;
+
+  CPythonWrapper *pThis = static_cast<CPythonWrapper *>(v8::Handle<v8::External>::Cast(info.Data())->Value());
+
+  v8::Handle<v8::Context> context(pThis->m_context);
+
+  v8::Context::Scope context_scope(context);
+
+  py::object obj = pThis->Unwrap(info.Holder());
+
+  v8::String::AsciiValue name(prop);
+
+  return handle_scope.Close(pThis->Wrap(obj.attr(*name)));
+}
+
+v8::Handle<v8::Value> CPythonWrapper::Setter(
+  v8::Local<v8::String> prop, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
+{
+  v8::HandleScope handle_scope;
+
+  CPythonWrapper *pThis = static_cast<CPythonWrapper *>(v8::Handle<v8::External>::Cast(info.Data())->Value());
+
+  v8::Handle<v8::Context> context(pThis->m_context);
+
+  v8::Context::Scope context_scope(context);
+
+  py::object obj = pThis->Unwrap(info.Holder());
+
+  v8::String::AsciiValue name(prop), data(value);
+
+  obj.attr(*name) = *data;
+
+  return handle_scope.Close(pThis->Wrap(obj.attr(*name)));
+}
+
+v8::Handle<v8::Value> CPythonWrapper::Caller(const v8::Arguments& args)
+{
+  v8::HandleScope handle_scope;
+
+  CPythonWrapper *pThis = static_cast<CPythonWrapper *>(v8::Handle<v8::External>::Cast(args.Data())->Value());
+
+  v8::Handle<v8::Context> context(pThis->m_context);
+
+  py::object self = pThis->Unwrap(args.This());
+
+  py::object result;
+
+  switch (args.Length())
+  {
+  case 0: result = self(); break;
+  case 1: result = self(pThis->Unwrap(args[0])); break;
+  case 2: result = self(pThis->Unwrap(args[0]), pThis->Unwrap(args[1])); break;
+  case 3: result = self(pThis->Unwrap(args[0]), pThis->Unwrap(args[1]), 
+                        pThis->Unwrap(args[2])); break;
+  case 4: result = self(pThis->Unwrap(args[0]), pThis->Unwrap(args[1]), 
+                        pThis->Unwrap(args[2]), pThis->Unwrap(args[3])); break;
+  case 5: result = self(pThis->Unwrap(args[0]), pThis->Unwrap(args[1]), 
+                        pThis->Unwrap(args[2]), pThis->Unwrap(args[3]),
+                        pThis->Unwrap(args[4])); break;
+  case 6: result = self(pThis->Unwrap(args[0]), pThis->Unwrap(args[1]), 
+                        pThis->Unwrap(args[2]), pThis->Unwrap(args[3]),
+                        pThis->Unwrap(args[4]), pThis->Unwrap(args[5])); break;
+  default:
+    throw CWrapperException("too many arguments");
+  }
+
+  return pThis->Wrap(result);
+}
+
+v8::Persistent<v8::ObjectTemplate> CPythonWrapper::SetupTemplate(void)
+{
+  v8::HandleScope handle_scope;
+
+  v8::Handle<v8::ObjectTemplate> clazz = v8::ObjectTemplate::New();
+
+  v8::Handle<v8::External> cookie = v8::External::New(this);
+
+  clazz->SetInternalFieldCount(1);
+  clazz->SetNamedPropertyHandler(Getter, Setter, 0, 0, 0, cookie);
+  clazz->SetCallAsFunctionHandler(Caller, cookie);
+
+  return v8::Persistent<v8::ObjectTemplate>::New(clazz);
+}
+
+#define TRY_CONVERT(type, cls) { py::extract<type> value(obj); \
+  if (value.check()) return handle_scope.Close(cls::New(value())); }
+
+v8::Handle<v8::Value> CPythonWrapper::Wrap(py::object obj)
+{
+  v8::HandleScope handle_scope;
+
+  if (obj.ptr() == Py_None) return v8::Null();
+  if (obj.ptr() == Py_True) return v8::True();
+  if (obj.ptr() == Py_False) return v8::False();
+
+  TRY_CONVERT(int, v8::Int32);
+  TRY_CONVERT(const char *, v8::String);
+  TRY_CONVERT(bool, v8::Boolean);
+  TRY_CONVERT(double, v8::Number);
+
+  v8::Handle<v8::Object> instance = m_template->NewInstance();
+  v8::Handle<v8::External> payload = v8::External::New(new py::object(obj));
+
+  instance->SetInternalField(0, payload);
+
+  return handle_scope.Close(instance);
+}
+py::object CPythonWrapper::Unwrap(v8::Handle<v8::Value> obj)
+{
+  v8::HandleScope handle_scope;
+  
+  if (obj->IsNull()) return py::object();
+  if (obj->IsTrue()) return py::object(py::handle<>(Py_True));
+  if (obj->IsFalse()) return py::object(py::handle<>(Py_False));
+
+  if (obj->IsInt32()) return py::object(obj->Int32Value());  
+  if (obj->IsString()) return py::str(*obj->ToString());
+  if (obj->IsBoolean()) return py::object(py::handle<>(obj->BooleanValue() ? Py_True : Py_False));
+  if (obj->IsNumber()) return py::object(py::handle<>(::PyFloat_FromDouble(obj->NumberValue())));
+
+  if (obj->IsObject())
+  {
+    v8::Handle<v8::External> field = v8::Handle<v8::External>::Cast(obj->ToObject()->GetInternalField(0));
+
+    return *static_cast<py::object *>(field->Value());
+  }
+  
+  throw CWrapperException("unknown object type");
+}

File src/Wrapper.h

+#pragma once
+
+#include <cassert>
+#include <stdexcept>
+
+class CPythonException : public std::runtime_error
+{
+protected:
+  CPythonException(const std::string& msg) : std::runtime_error(msg)
+  {
+
+  }
+public:
+  static void translator(CPythonException const& ex) 
+  {
+    ::PyErr_SetString(PyExc_UserWarning, ex.what());
+  }
+};
+
+class CWrapperException : public CPythonException
+{
+public:
+  CWrapperException(const char *msg) : CPythonException(msg)
+  {
+
+  }
+};
+
+class CPythonWrapper
+{
+  static v8::Handle<v8::Value> Getter(v8::Local<v8::String> prop, 
+                                      const v8::AccessorInfo& info);
+  static v8::Handle<v8::Value> Setter(v8::Local<v8::String> prop, 
+                                      v8::Local<v8::Value> value, 
+                                      const v8::AccessorInfo& info);
+  static v8::Handle<v8::Value> Caller(const v8::Arguments& args);
+protected:
+  v8::Persistent<v8::ObjectTemplate> m_template;
+  v8::Context *m_context;  
+
+  v8::Persistent<v8::ObjectTemplate> SetupTemplate(void);
+public:
+  CPythonWrapper(void) : m_context(NULL)
+  {    
+    m_template = SetupTemplate();
+  }
+  ~CPythonWrapper(void)
+  {
+    m_template.Dispose();
+  }
+
+  void Attach(v8::Context *context)
+  {
+    assert(context);
+    assert(!m_context);
+
+    m_context = context;
+  }
+  void Detach()
+  {
+    assert(m_context);
+
+    m_context = NULL;
+  }
+
+  v8::Handle<v8::ObjectTemplate> AsTemplate(void) { return m_template; }
+
+  v8::Handle<v8::Value> Wrap(py::object obj);
+  py::object Unwrap(v8::Handle<v8::Value> obj);
+};

File src/stdafx.cpp

+// stdafx.cpp : source file that includes just the standard includes
+// PyV8.pch will be the pre-compiled header
+// stdafx.obj will contain the pre-compiled type information
+
+#include "stdafx.h"
+
+// TODO: reference any additional headers you need in STDAFX.H
+// and not in this file

File src/stdafx.h

+// stdafx.h : include file for standard system include files,
+// or project specific include files that are used frequently, but
+// are changed infrequently
+//
+
+#pragma once
+
+// Modify the following defines if you have to target a platform prior to the ones specified below.
+// Refer to MSDN for the latest info on corresponding values for different platforms.
+#ifndef WINVER				// Allow use of features specific to Windows XP or later.
+#define WINVER 0x0501		// Change this to the appropriate value to target other versions of Windows.
+#endif
+
+#ifndef _WIN32_WINNT		// Allow use of features specific to Windows XP or later.                   
+#define _WIN32_WINNT 0x0501	// Change this to the appropriate value to target other versions of Windows.
+#endif						
+
+#ifndef _WIN32_WINDOWS		// Allow use of features specific to Windows 98 or later.
+#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
+#endif
+
+#ifndef _WIN32_IE			// Allow use of features specific to IE 6.0 or later.
+#define _WIN32_IE 0x0600	// Change this to the appropriate value to target other versions of IE.
+#endif
+
+#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
+// Windows Header Files:
+#include <windows.h>
+
+#pragma warning( push )
+#pragma warning( disable : 4100 ) // 'identifier' : unreferenced formal parameter
+#pragma warning( disable : 4244 ) // 'argument' : conversion from 'type1' to 'type2', possible loss of data
+#pragma warning( disable : 4512 ) // 'class' : assignment operator could not be generated
+
+#include <boost/python.hpp>
+namespace py = boost::python;
+
+#include <v8.h>
+
+#pragma comment( lib, "v8.lib" )
+#pragma comment( lib, "v8_base.lib" )
+#pragma comment( lib, "v8_snapshot.lib" )
+
+#pragma warning( pop )