# Yacas plugins

Plugins are dynamic libraries loaded at runtime. They are normally used to provide access to external libraries or applications. `Yacas` comes with a few plugins, such as the GSL plugin. This chapter contains the documentation generated for each plugin.

##

The file scanner plugin

The file scanner plugin allows the programmer to scan files and directories in the file system. It is currently supported for Unix-like and Windows systems.

To use the plugin, the plugin has to be loaded through:

    Use("filescanner");

The file scanner plugin offers one principal new function; `ScanFiles`. The prototype for this function is:

    ScanFiles(BaseDirectory,SubDirectory,CallFunction);

The arguments:

- `BaseDirectory` - the base directory to scan in
- `SubDirectory` - the sub-directory to scan in
- `CallFunction` - the call-back function

The call-back function should accept three arguments: the base directory, the file name and a boolean specifying if the file is a sub-directory.

The full file name can be obtained by concatenating the file name to the base directory. If the file is a sub-directory, the file name can be used as the name of the sub-directory in subsequent recursive calls to `ScanFiles`.

For example, the following definition of the function `tst` can be used as a third argument to `ScanFiles`, in order to scan directories recursively, printing file names of files in the directories.

    // File, print
    10 # tst(_a,_b,False) <-- Echo("File: ",b)
    // Directory, scan recursively
    20 # tst(_a,_b,True) <-- ScanFiles(a,b,"tst")

Then, if the `Yacas` source is in `/Users/ayalpink/yacas/`, one can call:

    ScanFiles("/Users/someone/yacas/","plugins","tst")

The first lines of output (in `Yacas` version 1.0.55) is:

    File: plugins/.cvsignore
    File: plugins/CVS/Entries
    File: plugins/CVS/Repository
    File: plugins/CVS/Root
    File: plugins/doc.txt

Here the scan went into the `CVS` sub-directory. Appending these file names to the base directory, `/Users/someone/yacas/`, would give the full path to the file.

##

The regular expressions plugin

This plugin allows for text processing using regular expressions. The GPL'ed package `pcre` is included for this purpose (pcre stands for Perl compatible regular expressions).

To use the plugin, the plugin has to be loaded through:

    Use("pcre");

The `pcre` plugin offers two principal functions: `PcreLexer` and `PcreNextToken`. `PcreLexer` sets up and initializes the tokenizer to scan for a set of regular expressions. A call to `PcreNextToken` returns the result of the scan in the current file, starting from the current position.

`PcreLexer` does not interfere with normal reading of a file. When normal read calls are made, the default tokenizer is used. The tokenizer set up by `PcreLexer` is only used when `PcreNextToken` is called.

The syntax for `PcreLexer` is:

    PcreLexer(tokens);

The argument `tokens` is a list of token definitions. A token definition in turn is a list, with the first element a string containing the regular expression, and the second containing an atom that can describe the type of the token (for easy recognition later).

Calling `PcreNextToken()` will then return the first matching token from the current input.

The following example sets up the tokenizer to recognize either an integer, or a word consisting only of lowercase letters.

    In> DllLoad("pcre")
    Out> True
    In> PcreLexer({{"[0-9]+",Integer},{"[a-z]+",Word}})
    Out> True
    In> FromString("123abc")PcreNextToken()
    Out> {"123",Integer}
    In> FromString("===abc")PcreNextToken()
    Out> {"abc",Word}

##

The GSL library plugin

This plugin provides access to functions from the GNU Scientific Library (GSL). See http://www.gnu.org/software/gsl/ for more information and for documentation on specific library functions.

##

The example plugin

This servers as an illustration of the plugin capability of Yacas. The plugin defines some functions operating on integers, floats, and on a custom structure type "`Bla`".

This is an example mini-API.

Function `AddTwoIntegers`(`arg1,arg2`), calls `int add_integers` (`int` `arg1`, `int` `arg2`)

Function `AddTwoDoubles`(`x,y`), calls `double add_doubles` (`double` `x`, `double` `y`)

Declared struct `Bla*`

Function `CreateBla`(`arg1,arg2`), calls `Bla* CreateBla` (`int` `arg1`, `int` `arg2`)

Function `BlaSetA`(`arg1,arg2`), calls `void BlaSetA` (`Bla*` `arg1`, `int` `arg2`)

Function `BlaGetA`(`arg1`), calls `int BlaGetA` (`Bla*` `arg1`)

##

The Forth plugin

This is the forth api.