Your Ad Here

Posted By

theroamingcoder on 01/25/10


Tagged

ruby embedding embedded IronRuby


Versions (?)

Embedding IronRuby


 / Published in: C#
 

Add references to : IronRuby.dll, IronRuby.Libraries.dll, Microsoft.Scripting.dll and Microsoft.Scripting.Core.dll

  1. using System;
  2. using System.Windows.Forms;
  3. using Microsoft.Scripting;
  4. using Microsoft.Scripting.Hosting;
  5. using IronRuby;
  6.  
  7. namespace IronRubyEmbedDemo
  8. {
  9. public partial class Form1 : Form
  10. {
  11. public Form1()
  12. {
  13. InitializeComponent();
  14. //Set the title of the form
  15. this.Text = "Hello World!";
  16. //Create the iron ruby engine
  17. ScriptEngine engine = IronRuby.Ruby.CreateEngine();
  18. ScriptScope scope = engine.CreateScope();
  19. //Set this form as the variable "form" in the engine
  20. scope.SetVariable("form", this);
  21. //Create a line of code to execute in the engine
  22. String code = "form.Text";
  23. //Execute the code
  24. ScriptSource script = engine.CreateScriptSourceFromString(code, SourceCodeKind.SingleStatement);
  25. Object result = script.Execute(scope);
  26. //Display the result
  27. MessageBox.Show(result.ToString());
  28. }
  29. }
  30. }

Report this snippet  

You need to login to post a comment.