Skip to content

Instantly share code, notes, and snippets.

@jschementi
Created December 14, 2009 03:53
Show Gist options
  • Save jschementi/255762 to your computer and use it in GitHub Desktop.
Save jschementi/255762 to your computer and use it in GitHub Desktop.
Action eachFrame = null;
_scope.TryGetVariable<Action>("each_frame", out eachFrame);
EachFrame = eachFrame;
Func<object, dynamic> eachObject = null;
_scope.TryGetVariable<Func<object, dynamic>>("each_object", out eachObject);
EachObject = eachObject;
CaptureAnimationCallbacks();
runtime.LoadAssembly(typeof(Canvas).Assembly); // loads PresentationFramework
runtime.LoadAssembly(typeof(Brushes).Assembly); // loads PresentationCore
runtime.LoadAssembly(GetType().Assembly); // loads this exe
_scope.canvas = _canvas;
_scope.window = this;
private ScriptEngine _rubyEngine;
private IronRuby.Runtime.RubyContext _rubyContext;
private dynamic _scope;
// Initialize IronRuby
var runtime = ScriptRuntime.CreateFromConfiguration();
_rubyEngine = Ruby.GetEngine(runtime);
_rubyContext = Ruby.GetExecutionContext(_rubyEngine);
_scope = _rubyEngine.CreateScope();
// redirect stdout to the output window
_rubyContext.StandardOutput = OutputBuffer;
// Run the code
var result = _rubyEngine.Execute(code, _scope);
// write the result to the output window
var output = string.Format("=> {0}\n", _rubyContext.Inspect(result));
OutputBuffer.write(output);
// add the code to the history
_history.AppendText(string.Format("{0}\n{1}", code, output));
using Microsoft.Scripting.Hosting;
using IronRuby;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment