Tuesday, May 05, 2009

DLR Hosting in Silverlight

The Dynamic Language Runtime is the framework created by Microsoft for building and running dynamic languages on the .NET framework on Mono. The major language implemented on top of the DLR is IronPython, with IronRuby rapidly heading towards completion.

As well as being a fine language for application development, the DLR has been designed to be easy to embed into .NET applications; to provide user scripting and extensible architectures.

The .NET framework comes in three distinct varieties:
  • The 'standard' .NET framework for the desktop and server computers
  • The .NET compact framework for running on mobile and gaming devices like the XBox 360
  • The CoreCLR which is included in Silverlight, the browser plugin
Of these three the DLR will run on the first and third. The compact framework lacks the Reflection.Emit libraries which the DLR uses for code generation.

Just as IronPython can be embedded in .NET applications it can also be embedded into Rich Internet Applications through Silverlight. User scripting of web applications is perhaps novel; but there could be many use cases.

This blog entry by Kirill Osenkov demonstrates one use case - by using the DLR to plot graphs from user provided mathematical expressions. The entry has a large example showing the C# code which hosts the DLR, plus a screenshot of a graph drawn by his live geometry application:
As you probably know, DLR is the dynamic language runtime that provides a common platform for dynamic languages and scripting in .NET. Their two main languages, IronPython and IronRuby, are available to develop your programs and also to be hosted in your programs. DLR hosting means that the users of your program can use scripting in any DLR language, for example to automate your program or to programmatically access the domain model of your application.

I was thinking about adding a capability to plot function graphs like y = cos(x) to my Live Geometry app, so I thought of hosting the DLR in Silverlight to compile and evaluate mathematical expressions.

Fortunately, DLR readily supports this scenario. And fortunately, Tomáš Matoušek, a developer on our IronRuby Team (part of Visual Studio Managed Languages), sits right around the corner from my office and was kind enough to provide great help when I had questions. Big thanks and kudos to Tomáš!

No comments:

Post a Comment

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