This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Ruby and the fly likes Calling scripting lang code from Java when non-strings parameters are required for script functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Languages » Ruby
Bookmark "Calling scripting lang code from Java when non-strings parameters are required for script functions" Watch "Calling scripting lang code from Java when non-strings parameters are required for script functions" New topic
Author

Calling scripting lang code from Java when non-strings parameters are required for script functions

Rooks Forgenal
Ranch Hand

Joined: Jun 05, 2009
Posts: 82
I don't really know but it seems like this is at least an intermediat question. I have this code below. The goal is to provide easy access to Ruby methods through my Java code. For the most part it works. Where I run into trouble is when the Ruby function expects any non-string as a parameter. Using this setup, I believe I am stuck useing strings as parameters right? How might I pass the script an array or a linked list? I think I may have bitten off more than I can chew when I choose to start this "for the heck of it" program.

Rooks Forgenal
Ranch Hand

Joined: Jun 05, 2009
Posts: 82
I am going to ask this in Ruby section... This can be deleted if it pleases you.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
jake benn wrote:I am going to ask this in Ruby section... This can be deleted if it pleases you.
We don't delete things unless there is "something wrong with them." And please don't ask the same question twice. If you would like, I can move you to Ruby and do it so this thread remains visible from "Java in General."
Rooks Forgenal
Ranch Hand

Joined: Jun 05, 2009
Posts: 82
OOPS. Sorry, I am still a bit new to the forums and it was an honest mistake. It wont happen again.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

invokeMethod on invocable takes Object type for args
http://java.sun.com/javase/6/docs/api/javax/script/Invocable.html#invokeMethod(java.lang.Object,%20java.lang.String,%20java.lang.Object...)

Your methods are unnecessarily forcing the args to be Strings.

CallSubclassMethod should also have a lower-case c to follow Java coding standards for method names.


A good workman is known by his tools.
Rooks Forgenal
Ranch Hand

Joined: Jun 05, 2009
Posts: 82
Quite right... I didn't know it could be Objects. Now everything works great. I am still trying to get familiar with this JRuby... I have here a few functions in Ruby that use basic stuff. I am testing my java interface to make sure it works well with all Ruby has to offer. Below is code for the program. Does anyone have any suggestions on some Ruby methods that I should test it against? Just simple ones please. I am having a hard time reading Ruby syntax. This "code like a duck" is really difficult when comming from Java.

I honestly don't even really know why I am trying to do this. I guess, because it is challenging and I am learning a ton. Thanks to every one on this sight who has helped. This is great practice.




 
GeeCON Prague 2014
 
subject: Calling scripting lang code from Java when non-strings parameters are required for script functions