Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Python scripts



Python scripts are a type of scripts which can be used in the library. Python scripts use the Jython library.

Script syntax creation

By default you must implement all the methods of the script interface.

  • You don't need to implement any method to get the Script context. The framework will take care of it under the hood

Example

Suppose the following Script interface:
      public interface Script {
        public int execute();
      }
To create the wrapper, you must use a PythonScriptWrapper:
      ScriptWrapper<Script> wrapper = new PythonScriptWrapper<Script>(){
      };
      Script script = wrapper.getScript();

      File file = new File(<our script file>);
      wrapper.installScript(file);

      int value = script.execute();
You can use for example the following script:
    def execute(self):
      return 10

Default package imports

The Jython library does not work very well with package imports. For example this construct will not work correctly:
      from my.package import *
To work around this problem, the library will try to get all the classes defined in a package in the ClassLoader, which means that if you have:
      wrapper.import("my.package.*");
You will effectively create constructs like:
      from my.package import ClassA
      from my.package import ClassB
      ...
However this will not work for the JDK class library which means that for example this will not work:
      wrapper.import("java.util.*");

Optimization level


The Jython engine does not support any optimization level.

Categories: impls

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