It's easy to make objects accessible to Rhino from Java using ScriptableObject.putProperty , but is there a way to open a top-level function? That is, can I make the scripts in Rhino call foo() and call the Java code?
ScriptableObject.putProperty
foo()
Umm ... yes you can . Perhaps I misunderstand your question (what do you mean by a โtop-level functionโ?), But if you exposed a Rhino Java object, you can call its methods.