Implementing Interfaces:

Showing 1-3 of 3 messages
Implementing Interfaces: Peter Ehrlich 10/14/12 11:40 PM
Hey -- new here to Java and to Mirah.  I'm experimenting with using it in combination with the LeJos project to control lego robotics.

Trying to implement this java code is giving me trouble.  Here's the spec from their tutorial:

Button.ENTER.addButtonListener(new ButtonListener() {
      public void buttonPressed(Button b) {
        LCD.drawString("ENTER pressed", 0, 0);
      }

      public void buttonReleased(Button b) {
        LCD.clear();
      }
    });


And here's my (failing) Mirah implementation.  Hopefully, there some dumb mistake that I just wouldn't think of:


class MyButtonListener
  implements ButtonListener

  def buttonPressed(b: Button):void
    LCD.drawString("ESC pressed", 0, 6)
  end

  def buttonReleased(b: Button):void
    LCD.drawString("ESC released", 0, 6)
  end
end

// and later:
listener = MyButtonListener.new
Button.ESCAPE.addButtonListener(listener)


It gives me the following error:


$ mirahc --java --classpath /Users/peter/Downloads/leJOS_NXJ_0.9.1beta-3/lib/nxt/classes.jar  test.mirah 
Parsing...
  test.mirah
Inferring types...
test.mirah:32: can't convert Mirah::JVM::Types::TypeDefinition into String
    Button.ESCAPE.addButtonListener(listener)
Mirah::InternalCompilerError: can't convert Mirah::JVM::Types::TypeDefinition into String
         infer at /Users/peter/.rvm/gems/jruby-1.6.7.2/gems/mirah-0.0.12-java/lib/mirah/typer/simple.rb:280
         infer at /Users/peter/.rvm/gems/jruby-1.6.7.2/gems/mirah-0.0.12-java/lib/mirah/typer/simple.rb:275
       resolve at /Users/peter/.rvm/gems/jruby-1.6.7.2/gems/mirah-0.0.12-java/lib/mirah/typer/simple.rb:324
          each at org/jruby/RubyHash.java:1186



See the full docs:

Cheers & Thanks for any help!
--Peter
Re: Implementing Interfaces: Nick Howard 10/15/12 11:20 AM
Hi,
Looks like you might have found a bug. Could you try compiling with --verbose and dumping the output in a gist/pastebin? It'd be helpful to have the full test.mirah file too.
--
-Nick Howard
http://blog.baroquebobcat.com/


Re: Implementing Interfaces: Peter Ehrlich 10/15/12 7:00 PM
You guys sure know how to do verbose! Here's the output and the source:


Thanks for the help