Reputation: 2309
Is there a way to retrieve a global variable defined by the script writer without actually executing the script? e.g only Compile the code
Upvotes: 0
Views: 219
Reputation: 41
If I understand you correctly, you essentially want to execute just some initial parts of script before executing something upon that. What I would do is the following, given that I operate on a scope variable instead of "global" variable.
[Test]
public void TestPythonDymanicCall()
{
string customScript = @"
scriptScopeVar1 = 3
def executeSomething():
global scriptScopeVar1
scriptScopeVar1 = scriptScopeVar1 + 1
".unindent();
var engine = Python.CreateEngine();
var scope = engine.CreateScope();
engine.Execute(customScript, scope);
Assert.AreEqual(3, engine.Execute("scriptScopeVar1", scope));
engine.Execute("executeSomething()", scope);
Assert.AreEqual(4, engine.Execute("scriptScopeVar1", scope));
}
Upvotes: 1