[IronPython] Execute<T> and IronPython

Leo Carbajal desleo at gmail.com
Fri Oct 3 09:12:24 CEST 2008


Howdy again,

According to the hosting spec each language defines how, and what, to return
at the end of a script when using Execute<T>, is there a way to do this on
IronPython? I've tried a couple of things, such as

from Dirt import *

def echo(x):
    return x

kitty = Cat()
kitty.Name = "Tito"
kitty.Meow()
kitty

As an alternative, I'm using the following with the above Python code.

 public static T GetObject<T>(string fileName, string objectName)
        {
            try
            {
                string path = String.Format("{0}{1}{2}.py", BaseDir,
@"\HostScripts\", fileName);
                ScriptSource source =
privateEngine.CreateScriptSourceFromFile(path);
                source.Execute();
                return
privateEngine.GetVariable<T>(privateEngine.GetScope(path), objectName);
            }
//catches ommitted for space
}

Cat tito = DynamicServices.GetObject<Cat>("MUDConfig", "kitty");
Console.WriteLine(tito.Name);

I'd like to load my configuration files\classes and handle 'serialization'
via Python scripts, for various reasons, and using Execute would prevent me
from having to pick and choose specific names. (I.E. Kitty - since that
would be hardcoded in the C# source)

---
V
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20081003/aebd785c/attachment.html>


More information about the Ironpython-users mailing list