Implementing Loadable Classes in Java

When the suffix '.pnut' is omitted in load() call, Pnuts interpreter tries to load a corresponding Java class as a precompiled script. In this case, the class must be a class that implements pnuts.lang.Executable interface.

The class name is the script name that replaces '/' with '.'. For instance, a script name is "lib/stream", lib.stream class is loaded if it exists. If the class is not found, then lib/stream.pnut is loaded.

In an implementation class of pnuts.lang.Executable interface, run(Context) method must be defined.

package my.package;
import pnuts.lang.*;

public class init implements Executable {
    public Object run(Context context){
      ...
    }
}

Then load("my/package/init") loads this class and executes the run(Context) method.

To know if precompiled scripts are used, give -v option to the pnuts command or set the property "pnuts.verbose" true.

In case a precompiled script is used.
% pnuts -v -r my/package/init
[loading my.package.init class]
In case no precompiled script is used.
% pnuts -v -r my/package/init
[loading file:/C:/test/my/package/init.pnut]