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 end def self.pre puts "before draw" end def self.draw puts "at begin draw" end end cls = TestRegister.become_java!
Here is the test:-
load "./register.rb" def setup size 200, 200 fred = TestRegister.new self # no_loop end def draw end
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