Glich - v0.3.0 Manual
Define module
Development v0.3.0 Manual Glich Script Statements Define module

Modules

Modules are a way of introducing named programming elements into a Glich script. These elements can be objects, functions, commands, etc. It does this in one of two ways:-

Statement module Format
module system:name;
module system:name { object obj_name1 obj_name2 ...; };

In the core language, the module block can only contain object definitions. Language extensions (such as the Hics extension) allow other definitions to be included.

Module Signature: system:name

A module is identified by its signature which consists of two parts:-

The signature is a text string with no spaces, but if it conform to the rules for a code name, it can be used without quotes.

A code name can contain letters, digits, the colon and underscore characters. It cannot start with a digit and must not contain spaces.

Statement: module (Read Immediately)

A module statement can be used to immediately read in the module's script. This is useful when the module contains code that must be run to set up the environment for the rest of the script. An example of this would be a math module that defines mathematical functions.

module Statement
ExampleOutput
// Script file: games/simon.glcs command simon(action) { write "Simon says: " + @quote(action) nl; };
// Script file: test_simon.glcs module "file:games/simon"; call simon("Jump around!"); Simon says: "Jump around!"

Statement: module (Introduce Contents)

A common use case for Glich is to read in a library of statements ready for for use by the host program. The use of modules is intended to reduce the need to read in all of the statements. A module statement will introduce the object's code name so that the actual module is only read if it is required.

module Statement
ExampleOutput
// Script file: test_mod.glcs object test_sum { values one two three; function sum { result = one + two + three; }; };
// Script file: test_run.glcs module file:test_mod { object test_sum; }; let ts = {test_sum 1, 2, 3}; write ts nl ts@sum; {test_sum 1, 2, 3}
6
Development v0.3.0 Manual Glich Script Statements Define module

Managed by WebPageLayout Validated by HTML Validator (based on Tidy)

27th September 2024