Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Script runtime usage



After you have created the wrapper around the script interface, you will be able to install a script file and execute the script.

Installing a script file


Installing a script file is performed through the ScriptWrapper.installScript(File).

For example:
      File file = new File(<our script file>);
      wrapper.installScript(file);
Note that you can perform again this method on the same ScriptWrapper instance if you want to change the Script. For example this will work:
      ScriptWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() {
      };
      Script Script = wrapper.getScript();

      File file = new File(<our first script file>);
      wrapper.installScript(file);
      int value = script.execute(10);

      file = new File(<our second script file>);
      value = script.execute(10);

Installing a script from a String


It is also possible to install a Script from a String rather than a file. For example:
      String theContent = "...the script content"
      wrapper.installScript(theContent);

Handling exceptions

Main Article: Exceptions handling

The way exceptions are handled for both the correctness of the method arguments and the execution of the script is managed by the ScriptWrapper.logExceptions(boolean):

Showing exceptions in a code editor


It is possible to show the first exception and the associated StackTrace in a CodeEditor.

Getting the script methods


It is possible to get the map of methods defined in the script by ScriptMethodInvoker.getInvocableMethods() and ScriptMethodInvoker.getInvocableMethodsByNames().

These two methods will return the methods available in the installed script (not limited to the ones define in the Script interface). See Method invocation to see how to use them.

Note that depending on the language, this Map can contain more methods than only those defined in the Script itself[2]
However they will still be available to be invoked
.

Configuring the script execution


It is possible to configure the way the underlying script execution runs:
  • By default, the script runs in the same Thread as the caller
  • It is possible to configure the framework for running the script in another Thread by ScriptWrapper.setExecutionMode(short)

Notes

  1. ^ By default they will be logged to the console
  2. ^ However they will still be available to be invoked

See also


Categories: api

Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence