title: Interfacing C# with IronPython - obtaining return values
body: <p>I'm trying to implement support for IronPython in a section of our application that uses scripting and currently supports a number of existing languages such as Lua.</p>
  
  <p>The scenario is that we need to both support return values from scripts (using the language's return or equivalent syntax) and also read on exit, and write before execution variables to be used throughout the script.</p>
  
  <p>The problem I'm having with IronPython is that it seems to not allow use of return in a script outside of a function. I can therefore wrap all scripts in a function, though this is messy as I then have to indent all the code, whilst that's not a massive problem in itself it appears that any variables referenced in the script are treated as function scope local variables, and that the GetVariable/SetVariable methods do not allow me to specify these as globals thus the now method wrapped script fails as it cannot find the variables set by GetVariable and SetVariable.</p>
  
  <p>So for example taking the script:</p>
  
  <pre><code>integerVar = integerVar + 10
  stringVar = stringVar + " modified"
  return true
  </code></pre>
  
  <p>Will not work directly, because the return statement fails due to not being in a method. Wrapping in a function:</p>
  
  <pre><code>def run():
      integerVar = integerVar + 10
      stringVar = stringVar + " modified"
      return true
  </code></pre>
  
  <p>Fails when the method is called with "Local variable 'integerVar' referenced before assignment", despite being set previously with SetVariable on the scope.</p>
  
  <p>Is there any way I can execute IronPython scripts in a way that allows me to both obtain any value returned from a return statement, and to be able to both set values to be manipulated by the script prior to execution, and obtain their values post execution?</p>