The Environment provides base functions for all script interpreters. It is automatically loaded by any interpreter upon startup.
Method | Description |
---|---|
execute() | Execute script code. |
exit() | Terminates script execution immediately. |
formatText() | Format a text with format qualifiers. |
getModule() | Resolves a loaded module and returns the Java instance. |
getScriptEngine() | Get the current script engine instance. |
help() | Open help page on addressed topic. |
include() | Include and execute a script file. |
loadJar() | Add a jar file to the classpath. |
loadModule() | Load a module. |
print() | Write a message to the output stream of the script engine. |
printError() | Write a message to the error stream of the script engine. |
readInput() | Read a single line of data from the default input stream of the script engine. |
toDouble() | Convert input to a Java double. |
toInt() | Convert input to a Java int. |
toString() | Convert input to a Java String. |
wrap() | Wrap a java instance. |
Object execute(Object data) throws ExecutionException
Execute script code. This method executes script code directly in the running interpreter. Execution is done in the same thread as the caller thread.
result of code execution
void exit([Object value]) throws ExitException
Terminates script execution immediately. Code following this command will not be executed anymore.
String formatText(String format, [Object arg1], [Object arg2], [Object arg3], [Object arg4], [Object arg5], [Object arg6], [Object arg7], [Object arg8], [Object arg9])
Format a text with format qualifiers. Using parameters you may format numbers and objects according to Formatter rules. Further inline tokens in the form ${identifier} will be replaced by script variables, system properties and environment variables.
formatted string
Resolves a loaded module and returns the Java instance. Will only query previously loaded modules.
resolved module instance or null
IScriptEngine getScriptEngine()
Get the current script engine instance.
IScriptEngine instance
void help([String topic])
Open help page on addressed topic. If the given topic matches a method or field from a loaded module, the definition will be opened. If the topic is unknown, a search in the whole eclipse help will be launched.
Object include(Object resource) throws ExecutionException
Include and execute a script file. Quite similar to eval(Object) a source file is opened and its content is executed. Multiple sources are available: "workspace://" opens a file relative to the workspace root, "project://" opens a file relative to the current project, "file://" opens a file from the file system. All other types of URIs are supported too (like http:// ...). You may also use absolute and relative paths as defined by your local file system.
result of include operation
boolean loadJar(Object location) throws MalformedURLException
Add a jar file to the classpath. Contents of the jar can be accessed right after loading. location can be an URL, a path, a File or an IFile instance. Adding a jar location does not necessary mean that its classes can be accessed. If the source is not accessible, then its classes are not available for scripting, too.
true
when input could be converted to a URL
Object loadModule(String moduleIdentifier, [boolean useCustomNamespace]) throws ExecutionException
Load a module. Loading a module generally enhances the script environment with new functions and variables. If a module was already loaded before, it gets refreshed and moved to the top of the module stack. When a module is loaded, all its dependencies are loaded too. So loading one module might change the whole module stack.
When not using a custom namespace all variables and functions are loaded to the global namespace, possibly overriding existing functions. In such cases the Java module instance is returned. When useCustomNamespace is used a dynamic script object is created and returned.In such cases the global namespace is not changed. The namespace behavior is also used for loading dependencies.
true
if functions and constants should not be stored to the global namespace but to a custom objectOptional: defaults to <false>.loaded module instance
void print([Object text], [boolean lineFeed])
Write a message to the output stream of the script engine.
true
to add a line feed after the textOptional: defaults to <true>.void printError([Object text], [boolean printOnce])
Write a message to the error stream of the script engine.
true
, the text in parameter will be printed only once and ignored in other calls of this method. If false
, it
will be printed in all cases.Optional: defaults to <false>.String readInput([boolean blocking]) throws IOException
Read a single line of data from the default input stream of the script engine. Depending on the blocking parameter this method will wait for user input or return immediately with any available data.
true
results in a blocking call until data is available, false
returns in any caseOptional: defaults to <true>.string data from input stream
Double toDouble(Object element)
Convert input to a Java double.
converted value
String toString(Object element)
Convert input to a Java String.
converted value
Object wrap(Object toBeWrapped, [boolean useCustomNamespace]) throws ExecutionException
Wrap a java instance. Will create accessors in the target language for methods and constants defined by the java instance toBeWrapped. If the instance contains annotations of type WrapToScript only these will be wrapped. If no annotation can be found, all public methods/constants will be wrapped. As some target languages might not support method overloading this might result in some methods not wrapped correctly.
true
if functions and constants should not be stored to the global namespace but to the return value onlyOptional: defaults to <false>.wrapped object instance or java class when put to global namespace