I''m completely new at IronRuby and I try to use it for writing GIMP plug-ins, using my GIMP# library (http://sourceforge.net/projects/gimp-sharp/). I have hacked up the following code: require "../../lib/gimp-sharp" require "mscorlib" class RubySample < Gimp::Plugin def initialize(args) super(args, ''RubySample'') end end puts ARGV[0] RubySample.new(ARGV) --- But I get the following error: unknown: wrong number or type of arguments for `initialize'' (ArgumentError) The Plugin class has a constructor that takes two arguments: an array of strings (the command line arguments) and a string. Does IronRuby have a different notion of arrays and/or strings than the CLR? If so, how do I convert them? Thanks, Maurits -- Posted via http://www.ruby-forum.com/.
Did anyone ever help you with this? -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Maurits Rijk Sent: Monday, October 27, 2008 8:44 AM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] IronRuby for GIMP I''m completely new at IronRuby and I try to use it for writing GIMP plug-ins, using my GIMP# library (http://sourceforge.net/projects/gimp-sharp/). I have hacked up the following code: require "../../lib/gimp-sharp" require "mscorlib" class RubySample < Gimp::Plugin def initialize(args) super(args, ''RubySample'') end end puts ARGV[0] RubySample.new(ARGV) --- But I get the following error: unknown: wrong number or type of arguments for `initialize'' (ArgumentError) The Plugin class has a constructor that takes two arguments: an array of strings (the command line arguments) and a string. Does IronRuby have a different notion of arrays and/or strings than the CLR? If so, how do I convert them? Thanks, Maurits -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
RubyArrays are not implicitly convertible to CLR arrays. You need something like: def to_string_vector array list = System::Collections::Generic::List[ClrString].new array.each {|x| list.add(x.to_s.to_clr_string) } list.to_array end Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Jim Deville Sent: Wednesday, October 29, 2008 4:04 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby for GIMP Did anyone ever help you with this? -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Maurits Rijk Sent: Monday, October 27, 2008 8:44 AM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] IronRuby for GIMP I''m completely new at IronRuby and I try to use it for writing GIMP plug-ins, using my GIMP# library (http://sourceforge.net/projects/gimp-sharp/). I have hacked up the following code: require "../../lib/gimp-sharp" require "mscorlib" class RubySample < Gimp::Plugin def initialize(args) super(args, ''RubySample'') end end puts ARGV[0] RubySample.new(ARGV) --- But I get the following error: unknown: wrong number or type of arguments for `initialize'' (ArgumentError) The Plugin class has a constructor that takes two arguments: an array of strings (the command line arguments) and a string. Does IronRuby have a different notion of arrays and/or strings than the CLR? If so, how do I convert them? Thanks, Maurits -- Posted via http://www.ruby-forum.com/. _______________________________________________ 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
Thanks! I''m still a bit surprised that one has to do the conversion explicitly. I would expect that either IronRuby uses CLR arrays (and strings) or would do the conversion implicitly for me. But as I said in my previous mail, I''m new to IronRuby and probably missing a whole bunch of design decisions and other relevant information. Regards, Maurits Tomas Matousek wrote:> RubyArrays are not implicitly convertible to CLR arrays. > > You need something like: > > def to_string_vector array > list = System::Collections::Generic::List[ClrString].new > array.each {|x| list.add(x.to_s.to_clr_string) } > list.to_array > end > > Tomas-- Posted via http://www.ruby-forum.com/.
FWIW I''ve used this helper method: class Array def to_clr_arr arr = System::Array.CreateInstance self[0].class.to_clr_type, self.length.to_clr_int self.each_with_index { |r, i| arr[i] = r } return arr end end Here''s the to_clr_int method: class Object def to_clr_int System::Int32.parse(self.to_s) end end On Thu, Oct 30, 2008 at 12:10 AM, Tomas Matousek < Tomas.Matousek at microsoft.com> wrote:> RubyArrays are not implicitly convertible to CLR arrays. > > You need something like: > > def to_string_vector array > list = System::Collections::Generic::List[ClrString].new > array.each {|x| list.add(x.to_s.to_clr_string) } > list.to_array > end > > Tomas > > -----Original Message----- > From: ironruby-core-bounces at rubyforge.org [mailto: > ironruby-core-bounces at rubyforge.org] On Behalf Of Jim Deville > Sent: Wednesday, October 29, 2008 4:04 PM > To: ironruby-core at rubyforge.org > Subject: Re: [Ironruby-core] IronRuby for GIMP > > Did anyone ever help you with this? > > -----Original Message----- > From: ironruby-core-bounces at rubyforge.org [mailto: > ironruby-core-bounces at rubyforge.org] On Behalf Of Maurits Rijk > Sent: Monday, October 27, 2008 8:44 AM > To: ironruby-core at rubyforge.org > Subject: [Ironruby-core] IronRuby for GIMP > > I''m completely new at IronRuby and I try to use it for writing GIMP > plug-ins, using my GIMP# library > (http://sourceforge.net/projects/gimp-sharp/). > > I have hacked up the following code: > > require "../../lib/gimp-sharp" > require "mscorlib" > > class RubySample < Gimp::Plugin > > def initialize(args) > super(args, ''RubySample'') > end > > end > > puts ARGV[0] > RubySample.new(ARGV) > > --- > > But I get the following error: unknown: wrong number or type of > arguments for `initialize'' (ArgumentError) > > The Plugin class has a constructor that takes two arguments: an array of > strings (the command line arguments) and a string. Does IronRuby have a > different notion of arrays and/or strings than the CLR? If so, how do I > convert them? > > Thanks, Maurits > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > 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 > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core >-- Michael Letterle [Polymath Prokrammer] http://blog.prokrams.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081030/1f529dba/attachment-0001.html>
Nice, the array conversion seems to work quite well. Right now I''m encountering the next problem. The Plugin base class (C#) has the follow signature: protected abstract IEnumerator<Procedure> ListProcedures(); How can I implement this in my IronRuby derived class? Of course I tried something like: def ListProcedures yield new Procedure(...) end However, this method never gets called. Thanks, Maurits -- Posted via http://www.ruby-forum.com/.
"yield" doesn''t do in Ruby what it does in C#. You''ll probably need to define your own enumerator class doing something like this: class ProcedureEnumerator include System::Collections::Generic::IEnumerator.of(Procedure) def initialize *proc_list @proc_list = proc_list @pos = 0 end def MoveNext @pos = @pos + 1 if @pos < @proc_list.length throw :IndexError if @pos < @proc_list.length end def Reset @pos = 0 end def Current @proc_list[@pos] end end def ListProcedure ProcedureEnumerator.new(Procedure.new(...)) end Alternatively, you could create a statically-typed list of Procedure and get an enumerator from that: list = System::Collections::Generic::List.of(Procedure) list.add(Procedure.new(...)) Finally, we''re shortly going to change the naming policy for overrides of CLS virtual methods. When this happens, you''ll need to define ProcedureEnumerator with the "rubified" method names: move_next, reset and current. -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Maurits Rijk Sent: Thursday, October 30, 2008 7:45 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby for GIMP Nice, the array conversion seems to work quite well. Right now I''m encountering the next problem. The Plugin base class (C#) has the follow signature: protected abstract IEnumerator<Procedure> ListProcedures(); How can I implement this in my IronRuby derived class? Of course I tried something like: def ListProcedures yield new Procedure(...) end However, this method never gets called. Thanks, Maurits -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Hi Curt, Curt Hagenlocher wrote:> "yield" doesn''t do in Ruby what it does in C#.Ah, I wasn''t aware of that.> You''ll probably need to define your own enumerator class doing something > like this:<snip>> def ListProcedure > ProcedureEnumerator.new(Procedure.new(...)) >endFor some weird reason my method ListProcedure never gets called. At first I thought it might have the wrong signature, so I tried to override the simplest function in the Plugin base class (public virtual void Init() {}), but even that didn''t work. Investigations will continue and of course all the help already given in this forum is very much appreciated! Thanks, Maurits -- Posted via http://www.ruby-forum.com/.
On Thu, Oct 30, 2008 at 10:12 AM, Curt Hagenlocher <curth at microsoft.com> wrote:> Finally, we''re shortly going to change the naming policy for overrides of CLS virtual methods. When this happens, you''ll need to define ProcedureEnumerator with the "rubified" method names: move_next, reset and current.I still do not like this decision. Any chance there could be a flag we could set to get back to using the normal .NET naming?
Do you know that your script is being loaded at all? How are you integrating with the extension model (which no doubt expects an assembly)? -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Maurits Rijk Sent: Thursday, October 30, 2008 8:50 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] IronRuby for GIMP Hi Curt, Curt Hagenlocher wrote:> "yield" doesn''t do in Ruby what it does in C#.Ah, I wasn''t aware of that.> You''ll probably need to define your own enumerator class doing something > like this:<snip>> def ListProcedure > ProcedureEnumerator.new(Procedure.new(...)) >endFor some weird reason my method ListProcedure never gets called. At first I thought it might have the wrong signature, so I tried to override the simplest function in the Plugin base class (public virtual void Init() {}), but even that didn''t work. Investigations will continue and of course all the help already given in this forum is very much appreciated! Thanks, Maurits -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Curt Hagenlocher wrote:> Do you know that your script is being loaded at all? How are youYes, I''m very sure. The IronRuby class uses the constructor of the base class, which has some print statements in it.> integrating with the extension model (which no doubt expects an > assembly)?I use a require statement to load my gimp-sharp.dll. This seems to work quite well because GIMP actually loads my IronRuby plug-in. Only problem I still have is that it doesn''t overload the abstract method ListProcedures, which means that the plug-in doesn''t register itself yet. Thanks, Maurits -- Posted via http://www.ruby-forum.com/.