Previous versions
The previous two Articles respectively introduced Google's V8 engine and open-source Javascript. NET (V8. NET Wrapper ). On the basis of the two, I made a high-level package (Efreda. script), and optimized some code to solve some exceptions of the original Wrapper. script has been updated to make it easier to use during development.
Custom ing alias
A friend who used this library told me that if it is not added to the global assembly, it would be quite troublesome to instantiate the. NET class in JS. For example, the following code should be used.
function testCreateByFullName(){var proc=$.Create("System.Diagnostics.Process, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",null);proc.StartInfo.FileName="calc";proc.Start();}
A long string of such names is required each time, which reduces the development efficiency.
If the global assembly is loaded at each program startup, the problem is also large, because the whole. NET assembly is quite a lot. In this case, it takes a lot of time and memory (about 5-10 seconds to load the Assembly, greatly reducing the program running efficiency ), although you can make a startup screen to let users wait, for some small programs, this approach is not a waste of resources.
I just saw an open source article. NET Script Engine, instantiated in the script. NET Class, which uses the alias method, so I also added this method again, you can add ing through code, you can also add through the configuration file, the Code is as follows.
Through the configuration file:
<ConfigSections> <section name = "Script" type = "Efreda. Script. ScriptSection, Efreda. Script"/> </configSections> <! -- Script engine configuration --> <! -- Parameter description: StartEngine: whether to start the Script Engine RelativePath: whether it is a relative path ScriptPath: Script directory. Enter the relative or absolute path according to RelativePath. You only need to enter the script directory name in the relative path to CreateGACMapping: whether to create a global assembly ing. This operation takes 5-10 seconds. If a ing is created, you can simply instantiate it in JS by specifying the name (namespace + class name. NET class, without specifying the strong name CreateMappingAsyn: whether to create a ing in asynchronous mode, avoid blocking the main thread --> <Script StartEngine = "True" RelativePath = "True" ScriptPath = "Scripts" CreateGACMapping = "False" CreateMappingAsyn = "False"> <Map Alias = "Process "Type =" System. diagnostics. process, System, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089 "/> </Script>
Code:
JScriptManager.AddMap("Math", "System.Math, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
Instantiate in a JS script:
function testACreate(){var proc=$.ACreate("Process",null);proc.StartInfo.FileName="calc";proc.Start();}function testAStaticMethod(){var arg=new Array();arg[0]=-25;var rtv=$.AStaticMethod("Math","Abs",arg);return rtv;}
Efreda. Script 0.2.2 source code download