views:

38

answers:

1

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?

+1  A: 

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);
Shay Friedman
But create a StreamReader and pass the StreamReader in instead of the stream. Then you can do this:my_yaml = YAML.load(self.my_stream_reader.ReadToEnd)
Kevin Radcliffe