Next: Function Locking, Previous: Private Functions, Up: Function Files

#### 11.8.4 Overloading and Autoloading

Functions can be overloaded to work with different input arguments. For example, the operator '+' has been overloaded in Octave to work with single, double, uint8, int32, and many other arguments. The preferred way to overload functions is through classes and object oriented programming (see Function Overloading). Occasionally, however, one needs to undo user overloading and call the default function associated with a specific type. The `builtin` function exists for this purpose.

— Loadable Function: [...] builtin (f, ...)

> Call the base function f even if f is overloaded to another function for the given type signature.

A single dynamically linked file might define several functions. However, as Octave searches for functions based on the functions filename, Octave needs a manner in which to find each of the functions in the dynamically linked file. On operating systems that support symbolic links, it is possible to create a symbolic link to the original file for each of the functions which it contains.

However, there is at least one well known operating system that doesn't support symbolic links. Making copies of the original file for each of the functions is undesirable as it increases the amount of disk space used by Octave. Instead Octave supplies the `autoload` function, that permits the user to define in which file a certain function will be found.

— Built-in Function: autoload (function, file)

> Define function to autoload from file.

> The second argument, file, should be an absolute file name or a file name in the same directory as the function or script from which the autoload command was run. file should not depend on the Octave load path.

> Normally, calls to `autoload` appear in PKG_ADD script files that are evaluated when a directory is added to the Octave's load path. To avoid having to hardcode directory names in file, if file is in the same directory as the PKG_ADD script then

>               autoload ("foo", "bar.oct");

> will load the function `foo` from the file `bar.oct`. The above when `bar.oct` is not in the same directory or uses like

>               autoload ("foo", file_in_loadpath ("bar.oct"))

> are strongly discouraged, as their behavior might be unpredictable.

> With no arguments, return a structure containing the current autoload map.

> See also: PKG_ADD.