Monday, March 23, 2009

Extending a .NET Application with the DLR: 3 Articles

Three different blog entries on extending an application by embedding IronPython and the Dynamic Language Runtime.
Creating a simple calculator program and an evaluator app that lets you enter code into a textbox and press a button to execute. Both embed IronPython and are available for download. These simple examples demonstrate how easy it is to add an embedded scripting language in a C# application.
Another simple example, but this one more directly aimed at those wanting to add scripting support into their applications:
There’s another interesting application for IronPython and IronRuby: adding scripting support for your existing .NET applications. This can be a very useful and powerful way to extend your applications and give the user freedom to program their own mini programs, scripts or whatever in your applications. It could be good for defining rules, assigning and calculating values, etc.

Usage of this class is pretty simple. You have to provide the object the script you want to execute and the input variables the script will have available as local variables. Once this is done, you have to call the Execute method, and this method will either return the output variables of the execution of the resulting script, or throw an exception.
This article is on... embedding IronPython and IronRuby. It's very short, but it does show the use of the ScriptRuntime (to get access to the clr module for the hosted engine).
For a more complete introduction to embedding IronPython and the DLR, you can either get IronPython in Action or read my embedding articles.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.