JavaEmbedUtils.newObjectAdapter().callMethod(object,"im");
----------------------------------------------------------

                 Key: JRUBY-5796
                 URL: http://jira.codehaus.org/browse/JRUBY-5796
             Project: JRuby
          Issue Type: Bug
    Affects Versions: JRuby 1.6.1
         Environment: Java 6, xp , JRuby 1.61
            Reporter: Manfred Quasten
            Assignee: Thomas E Enebo


I will use the Complex class from Ruby to calculate frequency response 
characteristic  and or Nyquist plots or what ever.

My java program will create a jruby script. The script will be executed for a 
lot of frequencies in a defined range and the plots can be created ...

The script can look like this: 

class IntegratingCircuit 
attr_writer :v
def f(s)
@v/s
end

end
IntegratingCircuit.new()



final ScriptBuilder builder = new 
RubyScriptBuilderImpl().withClassName("IntegratingCircuit").withWriteAccessor("v").withMethod("f(s)",
 "@v/s");
        
final Ruby ruby = Ruby.newInstance();   
                
final IRubyObject object= (IRubyObject) ruby.evalScriptlet(builder.build());
                
object.callMethod(ruby.getCurrentContext(), "v=" , new IRubyObject[]{ 
RubyFloat.newFloat(ruby, 100) });
                        
IRubyObject  result = object.callMethod(ruby.getCurrentContext(), "f", new 
IRubyObject[]{ RubyFloat.newFloat(ruby, 1d)});

This code work, but my problem is, that s isn't a real number it should have 
the type RubyComplex.



If i try to create a ComplexNumber it doesn't work :


IRubyObject object = JavaEmbedUtils.javaToRuby(ruby, 1d);
RubyComplex s = IJavaEmbedUtils.newObjectAdapter().callMethod(object,"im");
        
org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `im' for 
0:Fixnum

An othe trial was , to do it like this:

RubyComplex s = RubyComplex.newInstance(ruby.getCurrentContext(), 
RubyFloat.newFloat(ruby, 1d), RubyFloat.newFloat(ruby, 1d));

org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `real?' 
for 1.0:Float

Using irb the statement

pp 2.im() will give the result

Complex(0,2)


I workaround will be to execute a scriptlet Complex.new(s_re,s_im) but I think 
it should work directly from java.

What is going wrong ?









-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to