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 functions in Pnuts distribution are grouped into the following modules.

pnuts::lib
General purpose library
pnuts::gui
GUI library
pnuts::util
Utility functions
pnuts::servlet
Servlet library
pnuts::regex
Regular expression library

Dependency between modules

A module may depend on other modules. The dependency can be defined explicitly by a chain of use() call. For example, the relationship of the modules in Pnuts is as follows.

pnuts::servlet --> pnuts::util  +-->  pnuts::gui   ---->
                                +---------------------->  pnuts::lib
                                +-->  pnuts::regex ---->

The pnuts::util module depends on the pnuts::lib module. When pnuts::util is registered by calling use(), pnuts::lib is automatically registered by a subsequent use() call.

Steps to make a module

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. Insert 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")
    
    When autoload() is not defined, require("init") is needed. For example, when use("pnuts::lib") is not called directly or indirectly, autoload() is not defined.
  6. Archives the script files into a JAR file when you distribute the module.

Back