views:

322

answers:

4

What is the best tutorial, recipe, how-to, to embed a scripting language (like python, lua...) in another language (like c#)? Particularly, one that shows how to provide host-level elements in the script-level language (e.g. whenever someone accesses the attribute name of the object 'car' in python, the host application intercepts that call and returns the appropriate result).

+2  A: 

I wouldn't call this a tutorial, but its a damn fine example of how to do exactly what you're talking about -- using scripts and a scripting host to modify objects in the currently executing assembly.

http://blogs.microsoft.co.il/blogs/berniea/archive/2008/12/04/extending-your-c-application-with-ironpython.aspx

In this case, its IronPython as the scripting host in a C# application.

Will
+1  A: 

This article is a pretty straightforward look at the basic of embedding Python into a C program.

The official python documentation also covers it.

Dan
A: 

Thanks Will, great link! I'm still with a problem, though... You see, I need some kind of DynamicProxy for the objects. I cannot afford to have all the objects instantiated to provide the guest (scripting) language. Not until it needs them. I wonder if there is any "elegant" way to achieve this when using embedded scripting. Otherwise, I guess I'll just have to program it using Lazy strategies...

Hugo S Ferreira
A: 

"Falcon" is a programming language written in C++ and intended to be embedded in C++ applications, you might want to take a look at the falcon documentation, which also provides an "embedders guide", which also provides example source code.

none