Experiments with ruby-processing (processing-2.2.1) and JRubyArt for processing-3.0

Friday, 8 February 2013

Deep jruby voodo in ruby-processing

Finally I've cracked it, I can now call processing registerMethod (new since processing 2.0) directly from ruby processing. Requires a bit of jruby voodoo though (creating a java class from jruby) here is how I did with a simple test example:-
require 'jruby/core_ext'

class TestRegister

  def initialize parent
    parent.java_send :registerMethod, [Java::JavaLang::String, java.lang.Object], :draw, self
    parent.java_send :registerMethod, [Java::JavaLang::String, java.lang.Object], :pre, self

  def self.pre
    puts "before draw"

  def self.draw
    puts "at begin draw"


cls = TestRegister.become_java!

Here is the test:-
load "./register.rb"

def setup
  size 200, 200
  fred = TestRegister.new self
  # no_loop

def draw

Here is the result:-
before draw
at begin draw.........

pre is called before every draw....
So now you can do quite sophisticated things in a "ruby-processing" library for example, like you would have done in a java library (next to do is work it into my arcball library). Quandary is whether to make it more available to general ruby processing users (I think not for now, Im just amazed it worked...).

No comments:

Post a Comment


Blog Archive

About Me

My photo
I have developed JRubyArt and propane new versions of ruby-processing for JRuby- and processing-3.2.2