ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() { }; Script Script = wrapper.getScript(); wrapper.installScript(file); // do something with the scriptYou should do:
ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>(parentWrapper) { }; Script Script = wrapper.getScript(); wrapper.installScript(file); // do something with the scriptIn that case if the parent script wrapper is in a debug session, this script wrapper will be in a child session and will work correctly in the context of the debugger.
public interface Script { public int execute(int value) { } }You can for example declare a Groovy script wrapper for this script by:
ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() { }; Script Script = wrapper.getScript(); File file = new File(<our script file>); wrapper.installScript(file); int value = script.execute(10);Now you want to allow access to a scripted functions which correspond to another interface:
public interface Script2 { public int compute(int value) { } }The Groovy script wrapper for this script would be:
ScriptWrapper<Script2> wrapper = new GroovyScriptWrapper<Script2>() { };
public class CustomHelper implements ScriptHelper { private final ScriptContext context; public CustomHelper(ScriptContext context) { this.context = context; } public int compute(File scriptFile, int value) { ScriptWrapper<Script2> wrapper = new GroovyScriptWrapper<Script2>(context.getScriptWrapper()) { }; Script Script = wrapper.getScript(); wrapper.installScript(file); int value = script.compute(value); return value; }This allow to use any
Script2
script to perform the computation. For example, we could have the following Script
:public int execute(int value) { File scriptFile = context.getPath(<a Script2 script file>); int result = helper.compute(scriptFile, value); return result; }
DebuggingWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() { }; Script Script = wrapper.getScript(); File file = new File(<our script file>); DebugSession<Script> session = wrapper.createDebugSession(); SessionHook<Script> hook = new SessionHook<> { public Object start(Script script) { return script.execute(); } } session.setSessionHook(hook); session.startSession(); session.startScript(); // here the script.execute() method is effectively executed
Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence