I have a ScriptEngine instance which I use many times to execute scripts in different scopes:

I.e. repeat the following several times with different scripts

ScriptContext ctx = new SimpleScriptContext();
Bindings bindings = engine.createBindings();
ctx.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
engine.eval(someScript, ctx);

Some time later I want to invoke a top level function 'vertxStop' in one of those scripts.

Each script has their own version of function vertxStop as they all have their own scope.

According to the docs I can invoke a top level function by casting the engine to Invocable:

Invocable inv = (Invocable)engine;
inv.invokeFunction("vertxStop");

But this doesn't let me choose which of the many vertxStop functions I want to execute.

I looked for a version of invokeFunction which takes a ScriptContext too, but couldn't find one.

Does anyone know how I can invoke a top level function from a specific scope using the javax.script API?

Cheers


Reply via email to