Getting Started

This Pnuts User's Guide describes basic usage of Pnuts environment. Readers will learn what kind of functions are available and how to integrate Pnuts into Java applications.

This section explains some prerequisites to read the rest of the guide.

Runtime Environment

Pnuts runs on JRE (Java Runtime Environment) version 1.1 or later. The Pnuts distribution does not include JRE, which means you need to install a JRE (or JDK) in your computer before using Pnuts. If you have two or more JREs installed, you can pick one to use Pnuts every time you start a Pnuts interpreter by changing environment variables.

The pnuts.jar file is necessary to run the Pnuts interpreter. Also a shell script or a batch file is usually used to start it up. The pnuts.jar file contains standard scripts, which are described later, and classes in Pnuts API . Pnuts API is used to implement the pnuts command, in addition, developers can call them directly to incorporate the Pnuts' functionality into their applications.

Functions

Pnuts functions fall into two categories: built-in functions and others. It is important to distinguish them. Built-in functions are guaranteed to be available even when initialization script is not loaded and it is not permissible to re-define them. The Language Specification defines the built-in functions.

Modules

Module is a set of Pnuts scripts which can be utilized by applying the use() builtin function. A module corresponds to a package, in which functions of the module are defined.

The standard functions in Pnuts are grouped into pnuts::lib and pnuts::util module.

A module may depend on other modules. For example, pnuts::util module depends on pnuts::lib. When pnuts::util is loaded by use(), pnuts::lib is automatically loaded.

Custom modules of Pnuts can be made in the following steps.

  1. Name the corresponding package. e.g. "acme::util"
  2. Insert the statement; package("acme::util"), in the beginning of each script file.
  3. Save the script files in acme/util/*.pnut
  4. If the module depends on other modules, insert use() statement in acme/util/init.pnut. For example, if acme::util depends on pnuts::lib, the statement would be :
    use("pnuts::lib")
  5. Write require() or autoload() statements in acme/util/init.pnut, in order to load the scripts of the module.For example, if acme::util::play() function is defined in acme/util/cdplayer.pnut, the it would be:
    require("init")
    autoload("play", "acme/util/cdplayer")
    
    require("init") is needed because autoload() is not a builtin function, and it is defined in "init.pnut".
  6. Archives the script files into a JAR file when you distribute the module.

Convensions of This Guide

The User's Guide follows the following convension to show the usage of a function in a bounding box.

loadFile( String fileName )

This example shows that a function called 'loadFile' takes one parameter of String type.

When a function is overloaded, the possible signatures are connected with the word ' or '.

write(byte[] array , int offset , int length) or
(char[] array , int offset , int length)
An example of multiple signatures

When function has a optional parameter, a pair of curly brace { } is used to indicate it can be specified optionally.

open(String fileName {, String mode })
An example of optional Parameters

When a parameter is an array type, the component type can be omitted.

sort(array [ ] )


Back