C#下的JS脚本引擎ReoScript
2014-12-27 21:48
344 查看
在上一篇博文中,我写了一篇关于开源的表格控件ReoGrid的文章,点这里
我大致研究了一下它的执行脚本那块的功能,发现它使用了一个叫ReoScript的脚本引擎,并且也是一个开源项目,点这里
![](http://download-codeplex.sec.s-msft.com/Download?ProjectName=reoscript&DownloadId=770474)
通过上图,可以清晰的看到这个引擎的使用过程。
下面为集成到.net开发环境中的方法
![](http://download-codeplex.sec.s-msft.com/Download?ProjectName=reoscript&DownloadId=770539)
Prepare script, and run it by using ScriptRunningMachine:
![](http://download-codeplex.sec.s-msft.com/Download?ProjectName=reoscript&DownloadId=770528)
Result:
![](http://download-codeplex.sec.s-msft.com/Download?ProjectName=reoscript&DownloadId=770533)
There are some basic features provided by ReoScript core, such as Array.
![](http://download-codeplex.sec.s-msft.com/Download?ProjectName=reoscript&DownloadId=770534)
Result:
![](http://download-codeplex.sec.s-msft.com/Download?ProjectName=reoscript&DownloadId=770537)
![](http://download-codeplex.sec.s-msft.com/Download?ProjectName=reoscript&DownloadId=770772)
![](http://download-codeplex.sec.s-msft.com/Download?ProjectName=reoscript&DownloadId=770546)
![](http://download-codeplex.sec.s-msft.com/Download?ProjectName=reoscript&DownloadId=770551)
And there is a proxy class which provided for script:
![](http://download-codeplex.sec.s-msft.com/Download?ProjectName=reoscript&DownloadId=770552)
Then run script:
![](http://download-codeplex.sec.s-msft.com/Download?ProjectName=reoscript&DownloadId=770556)
![](http://download-codeplex.sec.s-msft.com/Download?ProjectName=reoscript&DownloadId=770567)
this feature available since v1.4
![](http://download-codeplex.sec.s-msft.com/Download?ProjectName=reoscript&DownloadId=770568)
ScriptVisible - There is a few difficult to control what objects and properties to be available in script. Consider that risk and choose this mode.
DirectAccess - This mode mix the world between .NET and Script, and script may become unavailable after you changed the appearance of .NET objects. So make sure that script available and choose this mode.
再下来就是怎么部署
2. Import the following namespace
3. Create ScriptRunningMachine and run script
我大致研究了一下它的执行脚本那块的功能,发现它使用了一个叫ReoScript的脚本引擎,并且也是一个开源项目,点这里
通过上图,可以清晰的看到这个引擎的使用过程。
下面为集成到.net开发环境中的方法
Run your script
Prepare script, and run it by using ScriptRunningMachine:
Result:
There are some basic features provided by ReoScript core, such as Array.
Result:
Add your objects and functions into script
3 ways to add objects and functions
Proxy objects
Without modifying your existed objects, add proxy objects for .NET objects will make it available in script. There is a .NET class named 'Car' and its proxy class named 'CarProxy', the 'CarProxy' class only be used for script.And there is a proxy class which provided for script:
Then run script:
Using ScriptVisible Attribute
Add 'ScriptVisible' attribute to class, field, property and method will make it visible to script.this feature available since v1.4
DirectAccess mode (.NET Reflection)
No need to write anything, just enable the DirectAccess mode of ScriptRunningMachin.Choose a way to integrate with your Application
Here are some tips that you can reference.Proxy objects - Although proxy objects need to be written, but this mode has a good reliability and it is very safety. If you are planning to provide script available for your end-user then you may choose this.ScriptVisible - There is a few difficult to control what objects and properties to be available in script. Consider that risk and choose this mode.
DirectAccess - This mode mix the world between .NET and Script, and script may become unavailable after you changed the appearance of .NET objects. So make sure that script available and choose this mode.
再下来就是怎么部署
Setup
1. Download ReoScript binary or build source file. Add the following DLLs into reference list of your project.Antlr3.Runtime.dll unvell.ReoScript.dll
2. Import the following namespace
using unvell.ReoScript;
3. Create ScriptRunningMachine and run script
ScriptRunningMachine srm = new ScriptRunningMachine(); srm.Run(...); // source can be string, file and stream
相关文章推荐
- C#实现JS脚本的escape()和unescape()
- 用正则表达式过滤脚本(js)的一些研究(asp.net + C#)
- 没有文件扩展".js"的脚本引擎 解决办法
- 点击“InstallWizardForVS2010.js” 弹出“ 没有文件扩展’.js‘的脚本引擎" 的解决办法
- 开源.NET(C#、VB.NET、J#等)脚本执行引擎(利用CodeDOM)
- js脚本调用C#程序
- 纯c#编写的脚本引擎(非CodeDom)
- 使 WebBrowser 更简单的新加和执行 js, 可安装 jQuery 脚本的 C# 开源代码 - IEBrowse...
- C# 将字符串作为语句执行(调用js引擎)
- 安装cocos2dx模板时,出现:输入错误: 没有文件扩展“.js”的脚本引擎。
- JS脚本判断是否支持Cookie,C#读取设置Cookie
- 使 WebBrowser 更简单的新加和执行 js, 可安装 jQuery 脚本的 C# 开源代码 - IEBrowser [1]
- C#winform后台代码与HTML内JS脚本函数相互调用
- (微软脚本引擎)C#利用msscript.ocx控件执行JS脚本
- C#利用js脚本实现配置的文本表达式计算
- 没有文件扩展“.js”的脚本引擎--解决办法
- Windows Script Control msscript.ocx c# .net 执行js 脚本
- Java6 脚本引擎(用Java调用JS脚本)调用js
- CScript 错误: 无法找到脚本“...js”的脚本引擎“JScript”
- C# webBrowser 屏蔽网页JS脚本错误弹窗