I’m completely new at IronRuby and I try to use it for writing GIMP
plug-ins, using my GIMP# library
(Gimp# download | SourceForge.net).
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?
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 M. 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
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.
You’ll probably need to define your own enumerator class doing something
like this:
def ListProcedure
ProcedureEnumerator.new(Procedure.new(…))
end
For 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!
Do you know that your script is being loaded at all? How are you
Yes, 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.
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?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.