开发者

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 开发者_如何学Gothe scripting engine?


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜