<div dir="ltr">Howdy again,<br><br>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<br>
<br>from Dirt import *<br><br>def echo(x):<br> return x<br> <br>kitty = Cat()<br>kitty.Name = "Tito"<br>kitty.Meow()<br>kitty<br><br>As an alternative, I'm using the following with the above Python code.<br>
<br> public static T GetObject<T>(string fileName, string objectName)<br> {<br> try<br> {<br> string path = String.Format("{0}{1}{2}.py", BaseDir, @"\HostScripts\", fileName);<br>
ScriptSource source = privateEngine.CreateScriptSourceFromFile(path);<br> source.Execute();<br> return privateEngine.GetVariable<T>(privateEngine.GetScope(path), objectName);<br>
}<br>//catches ommitted for space<br>}<br><br>Cat tito = DynamicServices.GetObject<Cat>("MUDConfig", "kitty");<br>Console.WriteLine(tito.Name);<br><br>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)<br>
<br>---<br>V<br></div>