I have an IronRuby script that modifies the value of a variable set via the ScriptScope
.
I'd like to retrieve the value of the variable after it's been modified, but I get the old value.
This is the code I have:
var engine = Ruby.CreateEngine();
var scope = engine.Runtime.CreateScope();
scope.SetVariable("y", 11);
var source = engine.CreateScriptSourceFromString("y=33; puts y;", SourceCodeKind.Statements);
source.Execute(scope);
The above code executes and outputs 33
to the console, which is OK.
However, I tried adding the following line after the above code:
Console.WriteLine(scope.GetVariable("y"));
and it outputs 11
, which is the original value.
Is there a way to get the new variable value?
With IronPython, to retrieve a value, I use a proxy object like this.
And I call SetVariable to pass an instance of the ScriptObject :
In your script you can set the result :