Search code examples
c#python.netironpythonpython.net

Creating an interactive shell for .NET apps and embed scripting languages like python/iron python into it


I was learning python using the tutorial that comes with the standard python installation. One of the benefits that the author states about python is "maybe you’ve written a program that could use an extension language, and you don’t want to design and implement a whole new language for your application" - My question is how would i go about designing a program (using c#) that can be extended using Python interactively(for this to be possible, i would imagine that i would need to create some sort of a "shell" or "interactive" mode for the .net program) ?

Are there any pointers on how to design .NET programs that have an interactive shell. I would then like to use python script in the shell to "extend" or interact with the program.

EDIT: This question partly stems from the demo give by Miguel de Icaza during PDC 2008 where he showed the interactive csharp command prompt, C# 4.0 i think also has this "compiler as a service" feature. I looked at that and thought how cool would it be to design a windows or web program in .NET that had a interactive shell.. and a scripting language like python could be used to extend the features provided by the program.

Also, i started thinking about this kind of functionality after reading one of Steve Yegge's essays where he talks about systems that live forever.


Solution

  • This sounds like a great use of IronPython.

    It's fairly easy to set up a simple scripting host from C# to allow calls into IronPython scripts, as well as allowing IronPython to call into your C# code. There are samples and examples on the CodePlex site that show how to do this very thing.

    Another good site for examples and samples is ironpython.info

    And here is a page dedicated to an example answering your very question, albeit in a generic DLR-centric way -- this would allow you to host IronPython, IronRuby, or whatever DLR languages you want to support.

    I've used these examples in the past to create an IronPython environment inside a private installation of ScrewTurn Wiki - it allowed me to create very expressive Wiki templates and proved to be very useful in general.