/ Published in: C#
Add references to : IronRuby.dll, IronRuby.Libraries.dll, Microsoft.Scripting.dll and Microsoft.Scripting.Core.dll
Expand |
Embed | Plain Text
using System; using System.Windows.Forms; using Microsoft.Scripting; using Microsoft.Scripting.Hosting; using IronRuby; namespace IronRubyEmbedDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); //Set the title of the form this.Text = "Hello World!"; //Create the iron ruby engine ScriptEngine engine = IronRuby.Ruby.CreateEngine(); ScriptScope scope = engine.CreateScope(); //Set this form as the variable "form" in the engine scope.SetVariable("form", this); //Create a line of code to execute in the engine String code = "form.Text"; //Execute the code ScriptSource script = engine.CreateScriptSourceFromString(code, SourceCodeKind.SingleStatement); Object result = script.Execute(scope); //Display the result MessageBox.Show(result.ToString()); } } }
You need to login to post a comment.
