On Global Variables in Hosted IronRuby

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);
This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">