Skip to content

Modules

A module always has the following file structure:

  • Directorysrc/
    • module.tl
  • Directoryres/
  • Directorytest/
  • tacho-module.toml

A module is the highest-level grouping of Tacholang code. Every module always has a tacho-module.toml file, which specifies the module information (name, version, description, authors, and other). The src folder contains all the code for that module, whilst the res folder contains resources that will be embedded into the compiled binary. At the root of the src folder, a module.tl file may be present. This file is required if the module is published as a library. The test folder is a special directory, which may contain unit-testing code. Files inside that folder are not included in compiled binaries and completely ignore all visibility modifiers of the module source code, allowing for extensive unit testing.

Modules are self-contained. The internal visibility modifier makes code visible only inside the current module, with no way to provide exceptions. Resources are also self-contained inside a module. If you wish to expose resources from your module to library consumers, you must provide functions which return the resources.

A module.tl file looks like this:

module.tl
// A module may be attributed. These attributes
// are retrievable during runtime.
// The module name must match the one in tacho-module.toml.
[some_attribute]
module module_name
//
// Options for library
//
// Set path for incoming connections.
library-path "/dev"
// Multiple option values may be present.
// Configure initial and max pool size.
library-pool-size 5 20
// Some options may be repeated. This makes the option appear as
// an array for the library definiting these options.
// Add path handlers.
library-handler mod.handlers.Warning "/warning"
library-handler mod.handlers.Note "/note"
// Options can also reference classes from another module.
library-handler generic_errors.ErrorHandler "/error"

Libraries may use the module.tl file as a sort of configuration file for their library. This is especially useful for libraries to set default values. Depending on the definition of the options in the library, these options may be present only during compile-time or be retrievable in runtime too.