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. |
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. |
listModules() | List all available (visible) modules. |
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. |
wrap() | Creates wrapper functions for a given java instance. |
java.lang.Object execute(java.lang.Object data)
Execute script code. This method executes script code directly in the running interpreter. Execution is done in the same thread as the caller thread.
Parameter | Type | Description |
---|---|---|
data | java.lang.Object | code to be interpreted |
Returns:java.lang.Object ... result of code execution
void exit([java.lang.Object value])
Terminates script execution immediately. Code following this command will not be executed anymore.
Parameter | Type | Description |
---|---|---|
value | java.lang.Object | return code Optional: defaults to <null>. |
java.lang.Object getModule(java.lang.String name)
Resolves a loaded module and returns the Java instance. Will only query previously loaded modules.
Parameter | Type | Description |
---|---|---|
name | java.lang.String | name of the module to resolve |
Returns:java.lang.Object ... resolved module instance or null
org.eclipse.ease.IScriptEngine getScriptEngine()
Get the current script engine instance.
Returns:org.eclipse.ease.IScriptEngine ... IScriptEngine instance
void help([java.lang.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.
Parameter | Type | Description |
---|---|---|
topic | java.lang.String | help topic to open (typically a function name) Optional: defaults to <null>. |
java.lang.Object include(java.lang.String filename)
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.
Parameter | Type | Description |
---|---|---|
filename | java.lang.String | name of file to be included |
Returns:java.lang.Object ... result of include operation
java.lang.String listModules()
List all available (visible) modules. Returns a list of visible modules. Loaded modules are indicated.
Returns:java.lang.String ... string containing module information
boolean loadJar(java.lang.Object location)
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.
Parameter | Type | Description |
---|---|---|
location | java.lang.Object | URL, Path, File or IFile |
Returns:boolean ... true
when input could be converted to a URL
java.lang.Object loadModule(java.lang.String identifier)
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.
Parameter | Type | Description |
---|---|---|
identifier | java.lang.String |
Returns:java.lang.Object ... loaded module instance
void print([java.lang.Object text], [boolean lineFeed])
Write a message to the output stream of the script engine.
Parameter | Type | Description |
---|---|---|
text | java.lang.Object | message to write Optional: defaults to <"">. |
lineFeed | boolean | true to add a line feed after the textOptional: defaults to <true>. |
void printError([java.lang.Object text])
Write a message to the error stream of the script engine.
Parameter | Type | Description |
---|---|---|
text | java.lang.Object | message to write Optional: defaults to <"">. |
java.lang.String readInput([boolean blocking])
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 available data.
Parameter | Type | Description |
---|---|---|
blocking | boolean | true results in a blocking call until data is available, false returns in any caseOptional: defaults to <true>. |
Returns:java.lang.String ... string data from input stream or null
void wrap(java.lang.Object toBeWrapped)
Creates wrapper functions for a given java instance. Searches for members and methods annotated with WrapToScript and creates wrapping code in the target script language. A method named <instance>.myMethod() will be made available by calling myMethod().
Parameter | Type | Description |
---|---|---|
toBeWrapped | java.lang.Object | instance to be wrapped |