Thibaut Barrère
2009-Feb-10 01:22 UTC
[Ironruby-core] How to implement a C# interface from Ruby ?
Hello again, I''m playing around with the idea of using IronRuby to implement plugins for a C#-based system (namely, CruiseControl.Net). I''m having some difficulties trying to figure out what the correct syntax for that would be. I''m currently using this to bootstrap the engine: var reader = new StreamReader("plugin.rb"); var code = reader.ReadToEnd(); reader.Close(); var engine = IronRuby.Ruby.CreateEngine(); engine.Execute(code); The code inside plugin.rb is trying to implement an existing C# interface: public interface IDoSomething { void HelloWorld(); } I tried: class Doer include IDoSomething def hello_world puts "hello" end end but it fails. What would be the correct syntax for a Ruby class to implement this ? thanks! -- Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090210/92830384/attachment.html>
Tomas Matousek
2009-Feb-10 01:41 UTC
[Ironruby-core] How to implement a C# interface from Ruby ?
Have you tried "def HelloWorld; end" (ie. match the interface method casing)? Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Thibaut Barr?re Sent: Monday, February 09, 2009 5:23 PM To: ironruby-core Subject: [Ironruby-core] How to implement a C# interface from Ruby ? Hello again, I''m playing around with the idea of using IronRuby to implement plugins for a C#-based system (namely, CruiseControl.Net). I''m having some difficulties trying to figure out what the correct syntax for that would be. I''m currently using this to bootstrap the engine: var reader = new StreamReader("plugin.rb"); var code = reader.ReadToEnd(); reader.Close(); var engine = IronRuby.Ruby.CreateEngine(); engine.Execute(code); The code inside plugin.rb is trying to implement an existing C# interface: public interface IDoSomething { void HelloWorld(); } I tried: class Doer include IDoSomething def hello_world puts "hello" end end but it fails. What would be the correct syntax for a Ruby class to implement this ? thanks! -- Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090209/65755b6b/attachment-0001.html>
Jimmy Schementi
2009-Feb-10 01:43 UTC
[Ironruby-core] How to implement a C# interface from Ruby ?
How does it fail? Nothing fails for me, but how are you trying to use this Ruby class? (test.cs has your c# code in it): C:\dev>csc.exe /t:library test.cs Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.715 for Microsoft (R) .NET Framework version 3.5 Copyright (C) Microsoft Corporation. All rights reserved. C:\dev>ir IronRuby 1.0.0.0 on .NET 2.0.50727.3521 Copyright (c) Microsoft Corporation. All rights reserved.>>> require ''test.dll''=> true>>> class Doer... include IDoSomething ... def hello_world ... puts "hello" ... end ... end => nil>>> Doer=> Doer>>> Doer.new=> #<Doer:0x000005c>>>> Doer.new.hello_worldhello => nil ~js From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Thibaut Barr?re Sent: Monday, February 09, 2009 5:23 PM To: ironruby-core Subject: [Ironruby-core] How to implement a C# interface from Ruby ? Hello again, I''m playing around with the idea of using IronRuby to implement plugins for a C#-based system (namely, CruiseControl.Net). I''m having some difficulties trying to figure out what the correct syntax for that would be. I''m currently using this to bootstrap the engine: var reader = new StreamReader("plugin.rb"); var code = reader.ReadToEnd(); reader.Close(); var engine = IronRuby.Ruby.CreateEngine(); engine.Execute(code); The code inside plugin.rb is trying to implement an existing C# interface: public interface IDoSomething { void HelloWorld(); } I tried: class Doer include IDoSomething def hello_world puts "hello" end end but it fails. What would be the correct syntax for a Ruby class to implement this ? thanks! -- Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090209/39471378/attachment.html>
Tomas Matousek
2009-Feb-10 01:45 UTC
[Ironruby-core] How to implement a C# interface from Ruby ?
You need to call the method from C# to check whether it is actually bound to the CLR interface implementation. The method will always be callable from Ruby. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jimmy Schementi Sent: Monday, February 09, 2009 5:43 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] How to implement a C# interface from Ruby ? How does it fail? Nothing fails for me, but how are you trying to use this Ruby class? (test.cs has your c# code in it): C:\dev>csc.exe /t:library test.cs Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.715 for Microsoft (R) .NET Framework version 3.5 Copyright (C) Microsoft Corporation. All rights reserved. C:\dev>ir IronRuby 1.0.0.0 on .NET 2.0.50727.3521 Copyright (c) Microsoft Corporation. All rights reserved.>>> require ''test.dll''=> true>>> class Doer... include IDoSomething ... def hello_world ... puts "hello" ... end ... end => nil>>> Doer=> Doer>>> Doer.new=> #<Doer:0x000005c>>>> Doer.new.hello_worldhello => nil ~js From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Thibaut Barr?re Sent: Monday, February 09, 2009 5:23 PM To: ironruby-core Subject: [Ironruby-core] How to implement a C# interface from Ruby ? Hello again, I''m playing around with the idea of using IronRuby to implement plugins for a C#-based system (namely, CruiseControl.Net). I''m having some difficulties trying to figure out what the correct syntax for that would be. I''m currently using this to bootstrap the engine: var reader = new StreamReader("plugin.rb"); var code = reader.ReadToEnd(); reader.Close(); var engine = IronRuby.Ruby.CreateEngine(); engine.Execute(code); The code inside plugin.rb is trying to implement an existing C# interface: public interface IDoSomething { void HelloWorld(); } I tried: class Doer include IDoSomething def hello_world puts "hello" end end but it fails. What would be the correct syntax for a Ruby class to implement this ? thanks! -- Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090209/9c6b4f85/attachment-0001.html>
Jimmy Schementi
2009-Feb-10 02:00 UTC
[Ironruby-core] How to implement a C# interface from Ruby ?
Ah, me = dummy. You have that interface in C#, and the IronRuby code you''re hosting can''t see the interface. This should expose all the types in the current assembly: engine.Runtime.LoadAssembly(GetType().Assembly); ~js From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jimmy Schementi Sent: Monday, February 09, 2009 5:43 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] How to implement a C# interface from Ruby ? How does it fail? Nothing fails for me, but how are you trying to use this Ruby class? (test.cs has your c# code in it): C:\dev>csc.exe /t:library test.cs Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.715 for Microsoft (R) .NET Framework version 3.5 Copyright (C) Microsoft Corporation. All rights reserved. C:\dev>ir IronRuby 1.0.0.0 on .NET 2.0.50727.3521 Copyright (c) Microsoft Corporation. All rights reserved.>>> require ''test.dll''=> true>>> class Doer... include IDoSomething ... def hello_world ... puts "hello" ... end ... end => nil>>> Doer=> Doer>>> Doer.new=> #<Doer:0x000005c>>>> Doer.new.hello_worldhello => nil ~js From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Thibaut Barr?re Sent: Monday, February 09, 2009 5:23 PM To: ironruby-core Subject: [Ironruby-core] How to implement a C# interface from Ruby ? Hello again, I''m playing around with the idea of using IronRuby to implement plugins for a C#-based system (namely, CruiseControl.Net). I''m having some difficulties trying to figure out what the correct syntax for that would be. I''m currently using this to bootstrap the engine: var reader = new StreamReader("plugin.rb"); var code = reader.ReadToEnd(); reader.Close(); var engine = IronRuby.Ruby.CreateEngine(); engine.Execute(code); The code inside plugin.rb is trying to implement an existing C# interface: public interface IDoSomething { void HelloWorld(); } I tried: class Doer include IDoSomething def hello_world puts "hello" end end but it fails. What would be the correct syntax for a Ruby class to implement this ? thanks! -- Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090209/2370f5af/attachment.html>
Jimmy Schementi
2009-Feb-10 03:15 UTC
[Ironruby-core] How to implement a C# interface from Ruby ?
// test.dll public interface IDoSomething { void HelloWorld(); } public class Foo { public void Bar(IDoSomething i) { i.HelloWorld(); } } C:\dev>ir IronRuby 1.0.0.0 on .NET 2.0.50727.3521 Copyright (c) Microsoft Corporation. All rights reserved.>>> require ''test.dll''=> true>>> class Doer... include IDoSomething ... def hello_world ... puts "hi" ... end ... end => nil>>> f = Foo.new=> #<Foo:0x000005c>>>> d = Doer.new=> #<Doer:0x000005e>>>> f.Bar(d)hi => nil From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Tomas Matousek Sent: Monday, February 09, 2009 5:46 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] How to implement a C# interface from Ruby ? You need to call the method from C# to check whether it is actually bound to the CLR interface implementation. The method will always be callable from Ruby. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jimmy Schementi Sent: Monday, February 09, 2009 5:43 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] How to implement a C# interface from Ruby ? How does it fail? Nothing fails for me, but how are you trying to use this Ruby class? (test.cs has your c# code in it): C:\dev>csc.exe /t:library test.cs Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.715 for Microsoft (R) .NET Framework version 3.5 Copyright (C) Microsoft Corporation. All rights reserved. C:\dev>ir IronRuby 1.0.0.0 on .NET 2.0.50727.3521 Copyright (c) Microsoft Corporation. All rights reserved.>>> require ''test.dll''=> true>>> class Doer... include IDoSomething ... def hello_world ... puts "hello" ... end ... end => nil>>> Doer=> Doer>>> Doer.new=> #<Doer:0x000005c>>>> Doer.new.hello_worldhello => nil ~js From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Thibaut Barr?re Sent: Monday, February 09, 2009 5:23 PM To: ironruby-core Subject: [Ironruby-core] How to implement a C# interface from Ruby ? Hello again, I''m playing around with the idea of using IronRuby to implement plugins for a C#-based system (namely, CruiseControl.Net). I''m having some difficulties trying to figure out what the correct syntax for that would be. I''m currently using this to bootstrap the engine: var reader = new StreamReader("plugin.rb"); var code = reader.ReadToEnd(); reader.Close(); var engine = IronRuby.Ruby.CreateEngine(); engine.Execute(code); The code inside plugin.rb is trying to implement an existing C# interface: public interface IDoSomething { void HelloWorld(); } I tried: class Doer include IDoSomething def hello_world puts "hello" end end but it fails. What would be the correct syntax for a Ruby class to implement this ? thanks! -- Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090209/5f468463/attachment.html>
Thibaut Barrère
2009-Feb-10 08:38 UTC
[Ironruby-core] How to implement a C# interface from Ruby ?
Hi guys, thanks for all the suggestions.> Ah, me = dummy. You have that interface in C#, and the IronRuby code you''re > hosting can''t see the interface. This should expose all the types in the > current assembly: > > engine.Runtime.LoadAssembly(GetType().Assembly); >That''s what was missing! Thank you... I''ll have a closer look at the hosting tests, I guess this was probably in there already. thanks! -- Thibaut> > > ~js > > > > *From:* ironruby-core-bounces at rubyforge.org [mailto: > ironruby-core-bounces at rubyforge.org] *On Behalf Of *Jimmy Schementi > *Sent:* Monday, February 09, 2009 5:43 PM > *To:* ironruby-core at rubyforge.org > *Subject:* Re: [Ironruby-core] How to implement a C# interface from Ruby ? > > > > How does it fail? Nothing fails for me, but how are you trying to use this > Ruby class? > > > > (test.cs has your c# code in it): > > > > C:\dev>csc.exe /t:library test.cs > > Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.715 > > for Microsoft (R) .NET Framework version 3.5 > > Copyright (C) Microsoft Corporation. All rights reserved. > > > > C:\dev>ir > > IronRuby 1.0.0.0 on .NET 2.0.50727.3521 > > Copyright (c) Microsoft Corporation. All rights reserved. > > > > >>> require ''test.dll'' > > => true > > >>> class Doer > > ... include IDoSomething > > ... def hello_world > > ... puts "hello" > > ... end > > ... end > > => nil > > >>> Doer > > => Doer > > >>> Doer.new > > => #<Doer:0x000005c> > > >>> Doer.new.hello_world > > hello > > => nil > > > > ~js > > > > *From:* ironruby-core-bounces at rubyforge.org [mailto: > ironruby-core-bounces at rubyforge.org] *On Behalf Of *Thibaut Barr?re > *Sent:* Monday, February 09, 2009 5:23 PM > *To:* ironruby-core > *Subject:* [Ironruby-core] How to implement a C# interface from Ruby ? > > > > Hello again, > > > > I''m playing around with the idea of using IronRuby to implement plugins for > a C#-based system (namely, CruiseControl.Net). > > > > I''m having some difficulties trying to figure out what the correct syntax > for that would be. I''m currently using this to bootstrap the engine: > > > > var reader = new > StreamReader("plugin.rb"); > > var code = reader.ReadToEnd(); > > reader.Close(); > > > > var engine > IronRuby.Ruby.CreateEngine(); > > engine.Execute(code); > > > > The code inside plugin.rb is trying to implement an existing C# interface: > > > > public interface IDoSomething { > > void HelloWorld(); > > } > > > > I tried: > > > > class Doer > > include IDoSomething > > > > def hello_world > > puts "hello" > > end > > end > > > > but it fails. What would be the correct syntax for a Ruby class to > implement this ? > > > > thanks! > > > > -- Thibaut > > _______________________________________________ > 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/20090210/f1f533a1/attachment.html>