In the previous article I tried to write less about features and more about what might be useful in isolation from scripting in general, so that the article was less similar to self-promotion. Literally, from the first comments, I realized that this was a mistake.
SpeedHe is fast. Very fast Over the past month, a lot of code has been cracked and a number of special cases analyzed and conclusions made. For example, depending on how the function is written and what language tools are used, it can be called up in one of more than 10 scenarios from equivalent inline to fair allocation of memory for each variable and argument and full context initialization.
Easy integrationThe entire heavy "kitchen" to provide access to platform types is hidden behind one modest function.
JSObject TypeProxy.Proxy(object)
You simply give away almost any object and assign the result to a variable.
var script = new Script(" megaObject.alert('Hello from javascript') "); script.Context.DefineVariable("megaObject") .Assign(TypeProxy.Proxy(new { alert = new Action<string>(x => MessageBox.Show(x)) }); script.Invoke();
For the types that implement the IList interface, there is a special wrapper
NiL.JS.Core.TypeProxing.NativeList , which masks such an object as a native js array.
You can register a type constructor and create objects already during the execution of the script. A variable with the type name is added.
script.Context.AttachModule(typeof(System.Windows.Forms.Form));
If you are too lazy to add types one at a time, you can add a whole namespace
Context.GlobalContext.DefineVariable ("forms") // , . .Assign(new NamespaceProvider ("System.Windows.Forms")); // , .
Not only performanceEach syntax tree node is accessible from outside the assembly. You can implement your virtual machine, a translator into another language, a static analyzer (if it is not integrated enough) or something else that your imagination is capable of. Each use of all variables stores a reference to the corresponding descriptor, which can tell some information about it. For example, show all the locations of use that have “survived” after optimization. A couple of weeks ago, the so-called Visitor was implemented with the help of which everything listed above is made even easier.