You can include the contents of a Glish source file using the include expression:
include "file"where file is the name of the file to include. Typically include expressions appear near the beginning of a source file, and include other source files as a simple ``library'' mechanism. include is an expression so the success of the inclusion can be checked like:
if ( ! include "my-first-file.g" ) include "my-fall-back-file.g"Here the file
my-fallback-file.g
is only included if the inclusion of
my-first-file.g
fails. If parsing any portion of the file being included
fails, no part of the file is executed.
include's may be nested arbitrarily deep, and the path that Glish searches when trying to include a file can be set as follows:
system.path.include := ". /home/me/scripts /usr/local/share/glish"Multiple directories can be specified with this variable, and they will be searched in the order specified. If this variable is not set, only the current directory will be searched for files which do not begin a ``
/
''. Note the leading dot
(``.
''); if this wasn't included the current directory would not be searched.
A good place to set this variable is in the .
glishrc file
(see § 11.1, page
While a Glish variable along with the is_defined() function (see
§ 9.6, page ) can be used to prevent multiple inclusions of a
file, a better way to handle this with the include once pragma.
When this pragma is inserted into a file, it indicates that the interpreter
should only include it once. The pragma is used as follows:
pragma include once print "file test_pragma.g included"This would force the file to only be included once. Currently, to include the file again the user must exit Glish. The advantage is that on successive includes of the file Glish can return without parsing or even opening the file. This saves time and the include file is simpler.