It's easy to make objects available to Rhino from Java using ScriptableObject.putProperty
, but is there a way to expose a top-level function? That is, can I make it so scripts in Rhino can call foo()
and have that call out to Java code?
views:
232answers:
1
+3
A:
Umm... yes, you can. Perhaps I'm not understanding your question correctly (what do you mean by "top-level function"?) but if you've exposed java object to Rhino, you can call its methods.
ChssPly76
2009-10-09 20:26:31
Sorry if I wasn't clear. While I can expose an object, which allows me to call foo.bar(), I'd ideally like to just call bar(). So, by 'top-level function' I mean a function that's a property of the Rhino Scope that's currently executing, if that makes more sense.
Thom
2009-10-09 20:32:35
Oh, I see. You can define a FunctionObject: https://www.mozilla.org/rhino/apidocs/org/mozilla/javascript/FunctionObject.html and associate it with global (or your current) scope via putProperty()
ChssPly76
2009-10-09 20:57:58
Superb, that looks perfect. Thanks!
Thom
2009-10-09 21:14:46