Loading Scripts

Loading from a Local File

loadFile ( file_name )

loadFile() reads a script file file_name from a local file systems. file_name can be absolute path or relative path from the "user.dir" property.

e.g.
loadFile("/home/pnuts/sample.pnut")
loadFile("..\\examples\\compose.pnut")

Loading from a Resource, File, URL

pnuts_load_path

The variable pnuts_load_path specifies the order in which a script file is searched. The value is an array of String, File, or URL object.

String Base of resource name
File Absolute path of a directory where a script file resides
URL Base of script file's URL
e.g.
import("java.io.*")
import("java.net.*")

pnuts_load_path = ["/lib", File("/tmp"), URL("http://host/dir/")]
load("script")

The default value of pnuts_load_path is ["/"].

load ( script )
require ( script )

load() reads script and evaluates it.

require() reads a script file if the file has not been read.

The suffix '.pnut' can be omitted for load() and require().

autoload ( function_name , script )
autoload ( [ function_name , ... ] , script )

autoload() associates name with a script so that when the value of variable name is null 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", "lib/ls")
autoload(["getProperty", "setProperty"], "lib/property")

Back