About scripting language usage in. Net

Source: Internet
Author: User
Tags lua

 基于.net中drl框架的脚本现在有很多,最近也由于工作的需要,目前有lua、python、ruby、javascript的.net实现,对ruby不怎么了解,python、lua、js就成了试验的对象。   先说lua怎么用吧
using (var L = new Lua ()) {//Create a LUA Script environment (global) var g = l.createenvironment (); g["mainform"] = this;g. Registerpackage ("Chart", typeof (Userchart)); G.dochunk (Application.startuppath + "\config.lua");}

  

  DuChunk也支持直接传入脚本的方法重载,通过字典的方法注入全局变量,个人挺喜欢lua的,但是lua的异常机制挺简单的通过  pcall保护方法来防止异常中断,也导致了不能很好的利用.net的异常机制。
Local getresponse= function () local response = Request. GetResponse () Response. Close () endlocal Status,err=pcall (getResponse)

  


The introduction of new assemblies is also quite cumbersome for the CLR. System.Reflection.Assembly:Load ("System.Windows.Forms, version=4.0.0.0, Culture=neutral, publickeytoken= b77a5c561934e089 ");
See this PublicKeyToken, big a bit big not, test a bit, indispensable.
Say JS again.
JS with the Ironjs open-source Https://github.com/fholm/IronJS, Ben kinda like, but see the official introduction, depressed, script and the host is the value of the transfer,
Originally using the script is not only to deal with some dynamic computing, but also can manipulate. NET objects, now see the value of passing, of course, can also curve the salvation, and then re-transfer back to the assignment is, can always feel, not neat, trouble, the results of their own test, the result is the value of the pass, the code is not left,

最后说说python   现在ironpython是支持python 2.7的,之前是微软官方支持,现在好像是也让民间来维护了,但我和他接触了也有几年了,可以说是.net中实现动态脚本最成熟的,和.net支持也是最好的,同时他的异常机制可以和.net也完美结合。通过[]来支持泛型,相关不错。
var engine = Python.createengine (); var env=engine. Runtime.globals;env. SetVariable ("MainForm", this), engine. Runtime.loadassembly (assembly.getassembly (typeof (int))), engine. Runtime.loadassembly (assembly.getassembly (typeof (MainForm))), engine. Runtime.loadassembly (assembly.getassembly (typeof (Color))); var code = engine. Createscriptsourcefromfile (Application.startuppath + "\config.py"); Code. Execute (env);

  

   引擎中引入程序集,挺方便的engine.Runtime.LoadAssembly(Assembly.GetAssembly(typeof(int)));

can also be referenced in scripts, which is much more convenient than Lua

Import CLR
Clr. AddReference ("System.Windows.Forms.DataVisualization")
Clr. AddReference ("System.Windows.Forms")
From System.Windows.Forms Import * #这个和C # using System.Windows.Forms one meaning.

个人最终选择python,主要是它目前与.net结合,基于dlr,动态语言运行时最成熟,结合项目是最稳健的做法,但个人对python始终没有好感,主要其缩进的格式和GIL(导致不能多核问题),让我无比之不喜欢,下一篇写一下几种语言的一个比较和个人看法吧

About scripting language usage in. Net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.