[Ironruby-core] Passing a .NET object to the RubyEngine...

Eric Nicholson enicholson at gmail.com
Fri Sep 28 10:55:27 EDT 2007


Well, technically between Ruby and VB.Net, but yeah, absolutely, works quite
well too.

The string above is actually a "real" object the way Ruby sees it, so it's
basically the same.  I'll put a quick example together if no one beats me to
it.

-Eric

On 9/28/07, Stefan Hüttenrauch <stefan.huettenrauch at hpi.uni-potsdam.de>
wrote:
>
>  Nice stuff Eric,
>
>
>
> Have you already passed real objects back and forth between Ruby and C#??
> That would be the real cool stuff. I will hack a little tomorrow I guess,
> but if you have any tips already, that would be great.
>
>
>
> Thanks
>
> Stefan
>
>
>
> *From:* ironruby-core-bounces at rubyforge.org [mailto:
> ironruby-core-bounces at rubyforge.org] *On Behalf Of *Eric Nicholson
> *Sent:* Freitag, 28. September 2007 15:40
> *To:* ironruby-core at rubyforge.org
> *Subject:* Re: [Ironruby-core] Passing a .NET object to the RubyEngine...
>
>
>
> Whoops ... missing some semicolons there.  Can you tell I spend most of my
> day in VB.NET?
>
> On 9/28/07, *Eric Nicholson* < enicholson at gmail.com> wrote:
>
> Here's a quick example:
>
> RubyEngine re = RubyEngine.CurrentEngine;
> IScriptModule mod = ScriptDomainManager.CurrentManager.Host.DefaultModule
>
>   string script = "puts 'Ruby and ' + var.to_s + ' together at last'"
>
>  mod.SetVariable("var", ".NET")
>
>   re.ExecuteCommand(script, mod);
>
> A couple things to note:
> 1. var.to_s is necessary because I don't think IR is coercing CLR Strings
> to Ruby Strings yet.
> 2. I'm not sure why you need to pass in the default module to
> ExecuteCommand, but I wasn't able to evaluate the variable in Ruby
> otherwise.
>
> -Eric
>
> On 9/28/07, *Phil Haack* <haacked at gmail.com> wrote:
>
>   Hi All, I posted some code for calling IronRuby code I found in the
> mailing list onto the wiki.
>
>
>
> http://ironruby.rubyforge.org/wiki/wiki.pl?ExecutingIronRubyFromCSharp
>
>
>
>   RubyEngine re = RubyEngine.CurrentEngine;
>
>   string script = "s = 'let us get started'" + Environment.NewLine
>
>     + "i = s.length");
>
>   re.ExecuteCommand(script);
>
>
>
> The only thing is, I don't know how to pass a .NET object to the context
> of the RubyEngine so it can be called from within the script. I'd like to
> update the example with that.
>
>
>
> Any help?
>
>
>
> Phil
>
>
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
>
>
>
>
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20070928/dac01851/attachment.html 


More information about the Ironruby-core mailing list