从.NET应用程序中引用谷歌的V8引擎 [英] Referencing Google's V8 engine from a .NET app

查看:1296
本文介绍了从.NET应用程序中引用谷歌的V8引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个.NET 3.5应用程序,有需要评估在服务器上JS code - 基本上用户提供规则集,可以在浏览器或服务器上的工作。托管的JS是不是一种选择,因为JS code会在运行时提供。 Aptana的Jaxer的也不是一个选项。所以我一直在寻找到使用中我的应用程序的V8发动机的版本。

I'm building a .NET 3.5 application and have the need to evaluate JS code on the server - basically a user provided rule set that can work within a browser or on the server. Managed JS is not an option, because the JS code would be provided at runtime. Aptana's Jaxer is also not an option. So I was looking into using a build of the V8 engine within my app.

我建源成功打入一个DLL,但该DLL不是不是一个托管库,而不是COM无论是。 V8只是普通的C ++。

I built the source successfully into a DLL, but that DLL is not not a managed library and is not COM either. V8 is just plain C++.

任何想法如何互操作此类型的DLL在C#中?此外,我接受其他建议的SpiderMonkey或另一个JS引擎。

Any ideas as to how to interop with this type of DLL in C#? Also, I'm open to other suggestions for SpiderMonkey or another JS engine.

在此先感谢。

更新:

我能够用Ryan的解决方案。我刚刚更新了引用构建从主干上的最新。它的工作太棒了。感谢瑞安。

I was able to use Ryan's solution. I just updated the references to the build for the latest from trunk. It worked great. Thanks Ryan.

推荐答案

我意识到,这可能不是你的问题一个确切的答案,但我想我会把我2美分值得我怀疑很多人们曾经尝试这样做。

我把它通过使用混合模式C ++创建一个托管的包装工作。还有其他的方法来做到这一点,但我会尝试做一个完整的包装,可以从任何.NET语言中使用。

I got it to work by created a managed wrapper using mixed mode C++. There are other ways to do it, but I was going to attempt to make a full wrapper that could be used from any .Net language.

获取的lib以这样一种方式,它可被包括在一个混合模式项目来编译被一个挑战一点点。我不得不修改运行时库(在SConstruct文件)使用/ MD和/ MDD因此,这将是与/ clr开关兼容。

Getting the lib to compile in such a way that it could be included in a mixed mode project was a little bit of a challenge. I had to modify the runtime library (in the SConstruct file) used to /MD and /MDd so that it would be compatible with the /clr switch.

到目前为止,我只简单的脚本运行,因为我还没有实现回调,自定义方法,对象和这种。

So far I have only simple scripts running as I have not implemented callbacks, custom methods, objects and such.

下面是一个什么样的使用看起来像我的测试应用程序的一个快速的示例:

Here is a quick sample of what the usage looks like for one of my test apps:

V8DotNet.Shell shell = new V8DotNet.Shell();

shell.ExecuteScript(@"print('V8 version is: ' + version());");

它可以运行更复杂的脚本,像一个base64连接codeR罚款以及。但现在我只能从C ++侧添加自定义项目。

It runs more complicated scripts like a base64 encoder fine as well. But for now I can only add custom items from the c++ side.

我愿意提供更多信息+ code。如果有人有兴趣,我可能永远不会接这个项目备份。但是,恐怕这办法不多code进入这里后,所以我们会找到一些其他媒体像谷歌code或codePLEX。

I am willing to provide more information + code if anyone is interested as I may not ever pick this project back up. But, I'm afraid it way to much code to go into a post here so we would have to find some other medium like google code or codePlex.

编辑:


好了,我已经上传了code。我必须把免责声明本:的项目是非常早,我是一个业余的C ++充其量所以不要让你的希望来了。此外,该项目是创建/做只是后铬被释放,以便V8版本包含可能是老了。

OK, I've uploaded the code. I do have to put a disclaimer on this: The project is very early and I am an amateur at C++ at best so don't get your hopes up to much. Also, this project was created/done just after chrome was released so the version of v8 included may be old.

这是说,那就是: http://ryanscook.com/Files/V8-DotNet.zip(21.5 MB)

That said, here it is: http://ryanscook.com/Files/V8-DotNet.zip (21.5 MB)

在包中,你会发现感兴趣的以下项目:

In the package you'll find the following items of interest:

V8Net库\ V8.Net \ V8.Net.sln - 这   是已经被管理的溶液   C ++包装凸出和C#控制台应用程序   用于测试

V8Net-Library\V8.Net\V8.Net.sln - This is the solution that has the managed C++ wrapper proj and a C# console app for testing.

相关性\ V8 - 这是我的V8 code   我曾经建立的V8库。

Dependencies\V8 - This is my V8 code that I used to build the V8 lib.

希望它能帮助!

这篇关于从.NET应用程序中引用谷歌的V8引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆