views:

94

answers:

4

In the process of designing an application we've come to the conclusion that the user needs to be available to add custom behaviour to the program and we want to allow this through scripting, however, none of us got any experience embedding a scripting engine in an application and even less designing the application to succesfully allow the scripting to place.

We suppose that the key to making the application scriptable is to create a large set of events that the scripts can respond to, as well as exposing functions for the script to use. Instead of rushing into scripting recklessly we would prefer reading up on some resources on the topic.

We're looking for resources (preferably books) which covers the process of designing an application for scripting. Any advice would be awesome as well. More or less any advice on the topic would be nice.

If details of the project in question is needed just say so an I'll add a paragraph explaning more in-depth detail.

+2  A: 

How techy do you want to make your scripting?

If your users are happy to use .Net then this artice gives an introduction to making an extensible application.

http://www.developerfusion.com/article/4529/using-net-to-make-your-application-scriptable/

When I was investigating a similar thing a while back I also found the technical notes for the sharpdevelop application to be very helpful.

http://www.icsharpcode.net/TechNotes/ProgramArchitecture.pdf http://damieng.com/blog/2007/11/08/dissecting-a-c-application-inside-sharpdevelop

Martin
I initially started out with LUA since I'm familiar with already, but since the managed wrapper for it was counterintuitive and didn't provide much debugging info, I decided to try out dynamically compiling .NET code and I must say that I'm loving it.
Qua
+2  A: 

Embedding scripting capabilities into an application will depend very much on the language and technology that make up the application. In your case, developing with C# there are some interesting options because of the work on the Dynamic Language Runtime. You should probably take a look at the IronRuby and IronPython projects since they will provide the best overall integration with .NET applications since they are themselves implementations of the Ruby and Python scripting languages on the .NET platform. As my experience centers on Ruby predominantly I would look at the information on hosting IronRuby in a .NET application.

As far as a general book goes I would probably start here: Language Implementation Patterns: Create Your Own Domain-Specific and General Programming Languages. For specifics on IronPython there is this title from Manning: IronPython in Action. And for IronRuby there is this book still in Beta: IronRuby in Action.

This may also be a solid resource coming out of Microsoft's Professional Developer's Conference: Using Dynamic Languages to Build Scriptable Apps.

James Thompson
Why would I use IronRube/Pything instead of C#?
Qua
Because C# isn't designed to be used for scripting, it's intended to be compiled rather than interpreted. Python or Ruby might be easier to pick up for a user that is not a programmer. Even if the user is a programmer there may be reasons to adopt Ruby or Python since the scripts can be more concise and contain more logic and less talking to the compiler.
James Thompson
You may have a point there. I've no experience with neither Ruby nor Python. Which language the scripting is done it should be interchangable since you've the ability to use a CodeCompiler according to the language of preference.
Qua
In theory, since I've not tried I don't know for sure, you could write your own application API for integration with the DLR, which underpins both IronRuby and IronPython, and be able to support usage of any language available or eventually developed on top of the DLR. By leveraging the work Microsoft is putting into the DLR through the IronRuby and IronPython projects you could conceivably put yourself in a position to support a myriad of scripting languages that could actually work together.
James Thompson
+1  A: 

Can you wait for C# 4.0 and the DLR (or deploy the beta)?

See Application Extensibility and Embedded Scripting.

TrueWill
+1  A: 

How hard this is really depends on your requirements. It can be quite easy.

In my app, I built a small set of classes that exposed the basic data model that I wanted to be made available to scripts. I built a scripting manager that creates an instance of the IronPython engine, adds an instance of the data model's root object as a global, and loads and executes the script.

Now, in my case, I'm actually the one doing all the scripting. So I don't need any kind of fancy development environment or testbed application, and I have essentially zero security considerations. The problem would be a lot harder if I needed to worry about any of those things.

Robert Rossney