We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
varargs issues? (Read 1545 times)
varargs issues?
Feb 27th, 2009, 9:27am
 
I'm trying to use the proControll library (http://texone.org/procontroll/) with ruby-processing.

But when I try to set a callback for a button event, I get this error:

Exception in thread "Animation Thread" joy.rb:11:in `setup': no plug with arguments matching [class org.jruby.RubySymbol, class org.jruby.RubyFixnum, class org.jruby.RubyFixnum, class org.jruby.RubyFixnum] on object #<Java::Procontroll::ControllDevice:0x4693f9 @java_object=Logitech Chillstream PC> (NameError)


Below is my simple test program. I've tried several variations ("button_0" instead of :button_0, also fewer args), but, unfortunately, no joy :-)

The error occurs on the call to @joypad.plug. Can someone give me a clue?

Thanks!

require 'ruby-processing'
class Joystick < Processing::App
 load_java_library :procontroll
 include_package "procontroll"

 def button_0
   puts "Pressed!"
 end

 def setup
   @controll = ControllIO.get_instance(self)
   @joypad = @controll.get_device(0)
   @joypad.plug( :button_0, 0, 0, 0 );
 end

 def draw
 end
end
Joystick.new :title => "Joystick"
Re: varargs issues?
Reply #1 - Feb 28th, 2009, 5:11am
 
Ruby-Processing can sometimes have a little confusion calling java methods that are overloaded with different argument signatures. It's one of those fundamental differences between the languages, where Ruby allows you to pass different numbers of arguments to a given method, and Java dispatches to different methods, depending on the number and type of the arguments... Anyway, what going on here is that there are two different plug methods, with two different signatures (from the docs):

plug(i_object, i_methodName, i_eventType, i_intputDevice, i_input);
plug(i_methodName, i_eventType, i_intputDevice, i_input);

Try calling the first one instead, passing in five arguments with the object (self) being the first one. That's just a guess; I don't have a joystick to test it with. Good luck.

Re: varargs issues?
Reply #2 - Feb 28th, 2009, 7:16pm
 
Thanks! Calling @joypad.plug( self, 'button_0', 0, 0 ) works better (actually, only 4 args.. perhaps docs are wrong). But plug does a getDeclaredMethods() on the first argument to verify that 'button_0' is a callable method, but it doesn't find it, since it's a ruby method.

Is it possible, from ruby, to create a java-->ruby binding so java can transparently make callbacks to ruby?

Re: varargs issues?
Reply #3 - Mar 3rd, 2009, 3:45am
 
Uh oh, that might be a little trickier. It's definitely easier to access Java-land from Ruby-space than it is to cross the other way. I don't know of a way to expose a Ruby-defined method directly to Java. Here's what the JRuby folks have to say about the subject:

http://wiki.jruby.org/wiki/Java_Integration

Perhaps an easier thing to do would be to subclass the ControlIO in Ruby and replace that troublesome method with one that invokes callbacks in a slightly less dynamic way. Might be worth a shot.
Page Index Toggle Pages: 1