Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

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

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am going to ask this in Ruby section... This can be deleted if it pleases you.
 
Marshal
Posts: 69033
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OOPS. Sorry, I am still a bit new to the forums and it was an honest mistake. It wont happen again.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rooks Forgenal
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.




 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic