Search code examples
.netyamlironruby

Passing .Net Stream into IronRuby?


I am using IronRuby to parse Yaml files and then use the parsed document in C#. This is working fine for creating an engine (Ruby.CreateEngine()), and executing the YAML::load(File.open('myFile.yaml')).

But, this works well because I can hard-code a string for the file name when I execute a few lines of ruby code.

Now, I want to understand how to pass a stream from .Net in to have the Yaml parser load it. How do I do this with the scripting engine?


Solution

  • You can set a variable with a ScriptScope and then use it from the Ruby code. For example:

    ScriptEngine eng = Ruby.CreateEngine();
    ScriptScope scope = eng.CreateScope();
    scope.SetVariable("my_stream",stream);
    eng.Execute("self.my_stream.read() # or whatever...", scope);