<div>Hi, I have two questions regarding the IronPython 2.0 B3.</div>
<div> </div>
<div>1. I'm trying to expose only a few methods from my assembly, but I haven't the faintest idea how to do it. The best I can come up with is the following:</div>
<div> </div>
<div>import clr<br>clr.AddReference("CoolEngine")<br>def randomIntNoParams():<br> from CoolEngine.Engine.Scripting import ScriptManager<br> return CoolEngine.Engine.Scripting.ScriptManager.RandomInt()<br>
def randomIntOneParam(i):<br> from CoolEngine.Engine.Scripting import ScriptManager<br> return CoolEngine.Engine.Scripting.ScriptManager.RandomInt(i)<br>def randomIntTwoParams(i, j):<br> from CoolEngine.Engine.Scripting import ScriptManager<br>
return CoolEngine.Engine.Scripting.ScriptManager.RandomInt(i, j)<br>def randomIntThreeParams(i, j, k):<br> from CoolEngine.Engine.Scripting import ScriptManager<br> return CoolEngine.Engine.Scripting.ScriptManager.RandomInt(i, j, k)<br>
def randomIntThreeParamsNoReturn(i, j, k):<br> from CoolEngine.Engine.Scripting import ScriptManager<br> CoolEngine.Engine.Scripting.ScriptManager.RandomIntNoReturn(i, j, k)</div>
<div><br>But alas, it says <font size="1">"name 'CoolEngine' is not defined" . </font>What am I doing wrong there?</div>
<div> </div>
<div>2. I'm trying to create a module dynamically at runtime. I have the following code which I want to be placed in a module called "Script":</div>
<div> </div>
<div>import clr<br>clr.AddReference("System.Threading")<br>def Pause(milliseconds):<br> from System.Threading.Tasks import Task<br> Task.CurrentTask.Wait(milliseconds)</div>
<div>
<p>However, I have no idea how to get it into its own module from there, and including it in its own file called Script.py is out of the question; I have that code as a string resource in my assembly. </p>
<p>I'm doing the following:</p><b><font size="2">
<p>Engine.CreateScriptSourceFromString(</p></font><font color="#a31515" size="2"><font color="#a31515" size="2">
<p>"import imp\n"</p></font></font><font size="2">+</font><font color="#a31515" size="2"><font color="#a31515" size="2">
<p>"import sys\n"</p></font></font><font size="2">+</font><font color="#a31515" size="2"><font color="#a31515" size="2">
<p>"newModule = imp.new_module(moduleName)\n"</p></font></font><font size="2">+</font><font color="#a31515" size="2"><font color="#a31515" size="2">
<p>"exec(moduleSource, newModule.__dict__)\n"</p></font></font><font size="2"> +</font><font color="#a31515" size="2"><font color="#a31515" size="2">
<p>"sys.modules[moduleName] = newModule"</p></font></font><font size="2">, </font></b><font color="#2b91af" size="2"><font color="#2b91af" size="2">SourceCodeKind</font></font><b><font size="2">.Statements).Execute(scope);</font></b>
<p>where the moduleName variable is "Script" and the moduleSource is the above source code. However, I get the following message:</p>
<p>An unhandled exception of type 'Microsoft.Scripting.SyntaxErrorException' occurred in Unknown Module.</p>
<p>Additional information: unexpected token '\r'</p>
<p>Any ideas?</p>
<p> </p>
<p>-- <br>/"\<br>\ / ASCII RIBBON CAMPAIGN<br>X AGAINST HTML MAIL<br>/ \<br><br>This message has been encrypted with ROT-26. Any unauthorised decryption will result in prosecution to the full extent of the law. </p>
</div>