Hi,
I am new to both JRuby and Ruby itself, so excuse me if I stumble a bit
here. I had previously been using Jython and way in the distant past
Rhino. In both of these environments I could evaluate some script to
return a reference to a function (or some sort of invokable object).
The pseudo code is:
ScriptingEngine engine = new ScriptingEngine (…);
…
fun = engine.eval ()
…
fun.invoke (3.0, 1.2)
The point of the above was that it is generally much faster to
evaluate in this form (particularly if I am evaluating at high
frequency), than doing something like:
engine.eval ()
…
engine.eval (“foo(3.0, 1.2)”)
The context of this “requirement” is that I want to embed some code
fragment into a configuration, such as:
lambda (| a,b,c | aaa + 4bb + 5*c)
evaluate it and be able to call it thousands of times within java.
I am using the “core” interface, i.e. ScriptingContainer. Appreciate
feedback on how to accomplish this. I don’t mind having a temporary
solution should there not be a direct one right now.
For instance, could I take the code in the configuration and wrap it
into a class that could be called from java numerous times without
calling runScriptlet?
That is another thing I am not clear about. In Jython or Rhino I can
extend a java interface. I have seen how that is done within JRuby as
well. However, I am not sure how to call such a class from the java
side. I note that there are methods in ScriptingContainer such as:
callMethod(receiver, methodName, args, returnType)
Many thanks!
Jonathan