IronRuby


IronRuby09 Jan 2009 05:14 pm

As part of my NYC Code Camp presentation on hosting DLR languages, I’ve put together some samples (code here). I couldn’t find samples for setting and getting values with a scope’s GetVariable and SetVariable methods. SetVariable works, but modifying it’s value in the script doesn’t result in the changed value being returned to GetVariable. The solution seems to require a global variable be set using code similar to the following:

RubyExecutionContext ctx = Ruby.GetExecutionContext(scope.Engine);
ctx.DefineGlobalVariable("send_alert", false);

ScriptSource source = scope.Engine.CreateScriptSourceFromString(siteRule.Rule, SourceCodeKind.Statements);
source.Execute(scope);

bool sendAlert = (bool)ctx.GetGlobalVariable("send_alert");
ctx.DefineGlobalVariable("send_alert", false);
Presenting & IronPython & Boo & IronRuby07 Jan 2009 09:17 am