doSomething(int)
method can be provided by another script (which can even not be a Javascript script):myScript: function() { value = doSomething(10); return value; }
class JSScriptable |
---|
Modifier and Type | Method and Description |
---|---|
boolean | addExternalFunction(CachedMethodKey key, String methodName, ScriptWrapper wrapper)
Add a method existing in another ScriptWrapper as a function available in the Javascript script. Return true if the function could be found
Parameters key - the key of the method in the other script methodName - the function key as used in the Javascript script wrapper - the ScriptWrapper |
public interface ScriptGroovy { public int computeValue(int value); }And we want to use this method to implement the
doSomething
function in the Javascript script. We could have the following basic AbstractJSScriptable
:public class MyScriptable extends AbstractJSScriptable { };Now we could create the groovy wrapper:
ScriptWrapper<GroovyScript> groovyWrapper = new GroovyScriptWrapper<GroovyScript>(){ }; CachedMethodKey key = new CachedMethodKey("computeValue", Integer.class); JSScriptWrapper<Script> wrapper = new JSScriptWrapper<Script>(){ }; MyScriptable scriptable = new MyScriptable(); scriptable.addExternalFunction(key, "doSomething", groovyWrapper); wrapper.setScriptable(scriptable);The following script will call the
computeValue(int value)
method in the Groovy script:myScript: function() { value = doSomething(10); return value; }
Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence