views:

87

answers:

3

I want to embed iron ruby into a mud that I am creating and for some reason I'm having trouble finding the correct examples to get started.

All I want to do is create a game where 'you' the player will program bots in iron ruby and then I will interperet the code in c# and make the bots do what you want them to. Also, I want to make it so that the code can be parsed as a string as iron ruby code which I will then use to control the bots.

I understand the fact that the dlr and clr are two different things but can't find the sample. The actual game is a classic telnet server that I coded in C# from scratch and connects via strict telnet protocol.

It can be found here: pttmud.the-simmons.net : 4243 via a telnet client and it should work.

A: 

Not exactly Ruby, what below is what I to for IronPython (make sure the assemblies are referenced first):

        runtime = IronPython.Hosting.Python.CreateRuntime();
    }

    public void Run(string script, params object[] variables)
    {
        var scriptSource = runtime.GetEngineByFileExtension("py").CreateScriptSourceFromString(script, SourceCodeKind.Statements);
        var scope = runtime.GetEngineByFileExtension("py").CreateScope();

        foreach (var variable in variables)
            foreach (var property in variable.GetType().GetProperties())
                if (property.CanRead)
                    scope.SetVariable(property.Name, property.GetValue(variable, null));

        scriptSource.Execute(scope);

Here the most important element is the script engine. You can request it by different options (extension in my case), and create scripts from either in memory or on disc sources.

It's also possible to share variables, which is also shown.

I think there is a better way now in C# 4.0, since C# itself became a dynamic programming language.

sukru
+1  A: 

Look at this post: http://www.ironshay.com/post/make-your-application-extendable-using-the-dlr.aspx . It shows how to call IronRuby/IronPython code from C#.

Shay Friedman
A: 

Here's a complete example of how to run RSpec from C#.

http://gist.github.com/465677

Cucumber doesn't work, though.

Julian Birch