|
loadFile() reads and executes a script file fileName from a local file systems. It returns the result of last expression.
e.g. (Windows)
loadFile("..\\examples\\compose.pnut") loadFile(`..\examples\compose.pnut`)
e.g. (Unix)
loadFile("/home/pnuts/sample.pnut")
load() reads and evaluates a script and returns the result of the last expression. If Pnuts::getClassLoader(Context) returns a class loader, the load() function finds a script using the class loader. Otherwise, the system class loader is used to find a script.
require() reads a script file if the file has not been read.
The suffix '.pnut' can be omitted for load() and require().
When the property "pnuts.compiled.script.prefix" is set and the suffix '.pnut' is omitted in these calls, Pnuts interpreter tries to load a precompiled script as a Java class. The class name is the script name that '/' is replaced by '.' after the value of the property. For instance, a script name is "lib/stream" and the property "pnuts.compiled.script.prefix" is "pnuts.precompiled.", pnuts.precompiled.lib.stream class is loaded if it exists. The pnuts command defines the property as "pnuts.precompiled." by default.
To know if precompiled scripts are used, give -v option to the pnuts command or set the property "pnuts.verbose".
In case precompiled script is used.
% pnuts -v -e 'println("hello")' [loading pnuts.precompiled.init class] [loading pnuts.precompiled.lib.stream class] hello
In case precompiled script is not used.
% pnuts -v -e 'println("hello")' [loading /init.pnut] [loading /lib/stream.pnut] hello
See also "Compiling scripts from command line".
autoload ( String name , String filename ) or
|
autoload() associates name with a script so that when the variable name is not defined, script is loaded before the reference is resolved.
If an array is specified each element is applied.
The suffix '.pnut' can be omitted for autoload().
e.g.
autoload("ls", "pnuts/lib/ls") autoload(["getProperty", "setProperty"], "pnuts/lib/property")
parse ( String expression ) or
|
parse() parses a script and returns a pnuts.lang.Pnuts object, which can be executed later with its run() method. When an error occurs during the parsing, ParseException is thrown.