Lmod Glossary¶
This glossary defines key terms, components, and concepts used within the Lmod codebase and documentation.
- Cosmic¶
A singleton module in Lmod responsible for managing global configuration values and Lmod’s internal state or settings. It provides a centralized interface (e.g.,
cosmic:value(),cosmic:assign()) to get, set, and initialize these parameters, many of which are derived from environment variables (e.g.,LMOD_SITE_NAME,LMOD_TRACING) or Lmod’s configuration files. It acts as a central access point for global settings throughout the Lmod codebase.- DirTree¶
A class/module in Lmod that scans module file directory structures (as defined by
MODULEPATH). It builds a representation of the available modules by traversing these directories, identifying modulefiles, and noting associated version or.modulercfiles. This hierarchical tree of directories and modulefiles is then utilized by other Lmod components, such asMNameandModuleA, to discover, locate, and understand the available software modules.- FrameStk¶
(Frame Stack) A singleton class managing a stack of “frames,” where each frame typically represents the evaluation context of a currently processing modulefile. This stack is crucial for Lmod to:
Track the nesting depth of modulefile evaluations (e.g., module A loading module B).
Provide access to context-specific data, such as the relevant
MT(Module Table) orVarT(Variable Table) for the active module.Implement control flow operations within modulefiles, such as the
breakcommand, by allowing Lmod to unwind or alter the evaluation sequence based on the current stack state.Offer traceback capabilities for debugging or error reporting.
Common operations include
push()when entering a module context andpop()when exiting.For a detailed explanation of its role in state management, see FrameStk: The Engine of Reversible State.
- Hub¶
A central singleton object, with its logic primarily defined in
src/Hub.lua. It acts as the main engine for Lmod’s operations concerning modules. Its responsibilities include:Orchestrating the loading (
hub:load()) and unloading (hub:unload()) of modules.Enforcing Lmod’s rules during these operations, such as handling already loaded modules, checking for conflicts, and managing dependencies (
hub:dependencyCk()).Providing information about modules, such as listing available modules (
hub:avail()) or their overview (hub:overview()).Managing the overall module state, including reloading all modules (
hub:reloadAll()) or refreshing the shell aiases and functions (hub:refresh()).
It is called by MainControl methods (e.g.,
M.load()callshub:load()) and is a critical component in the sequence of actions Lmod takes to manage the user’s environment.- l_usrLoad()¶
A local Lua function defined within
src/cmdfuncs.lua, specifically as a helper function called byLoad_Usr(). Its primary responsibilities are:To process the array of module name arguments (
argA) passed from the command line.To distinguish between modules to be loaded and modules to be unloaded (those prefixed with a minus sign), sorting them into separate internal lists.
To convert these module name strings (e.g., “foo/1.0”) into
MNameobjects, which are Lmod’s internal representation for modules.It accepts a
check_must_loadboolean parameter, which dictates whether Lmod should verify at the end of the process if all requested modules were successfully loaded.
- LMOD_CMD¶
An environment variable that stores the absolute path to the main Lmod executable script (typically named
lmod). This variable is essential for the correct functioning of themodulecommand. Shell initialization scripts (e.g., for bash, tcsh, zsh) use$LMOD_CMDto define themoduleshell function or alias, which then calls the Lmod executable, passing user commands and arguments to it. For example, in bash, the module function is often defined like:module () { eval "$($LMOD_CMD shell "$@")"; }. It must be correctly set in the user’s environment for Lmod to be invoked.- lmodCmdA¶
A Lua table defined in the
lmod.in.luascript. It serves as a primary dispatch table for Lmod, mapping user-provided command strings (e.g., “load”, “avail”, “list”, “purge”) to internal Lmod data structures or function entry points. When a user issues amodule <command> ...instruction, Lmod consultslmodCmdAto find the entry corresponding to<command>. This entry then directs Lmod to the appropriate internal table (likeloadTbl) or function (likeLoad_Usr()found insrc/cmdfuncs.lua) responsible for handling that specific action.- Load_Usr()¶
A function defined in
src/cmdfuncs.luathat serves as the primary entry point for handling user-initiatedmodule loadcommands (and similar commands likemodule try-load). Its main sequence of operations includes:Receiving the module names and any options specified by the user on the command line.
Calling the local helper function
l_usrLoad()to parse these arguments.l_usrLoad()separates them into lists of modules to load and unload, and converts the names intoMNameobjects. It is typically called withcheck_must_loadset to true for standard loads.Invoking
mcp:load_usr(lA)(wheremcpis the Main Control Program object andlAis the list ofMNameobjects to load), which then delegates toM.load_usr()insrc/MainControl.luato continue the loading process.
- loadModuleFile()¶
A function defined in
src/loadModuleFile.luathat is responsible for the direct processing and evaluation of an individual modulefile. Its key tasks include:Reading the entire content of the specified modulefile.
Detecting if the modulefile is a TCL-based module. If so, it invokes the
runTCLprog()routine to convert the TCL commands into an equivalent Lua script.Taking the modulefile content (which is now guaranteed to be Lua code, either originally or after conversion) and evaluating it within a controlled environment using the
sandbox()mechanism. Thesandbox()restricts the Lmod and Lua functions available to the modulefile.
It is primarily called from
src/Hub.luaduring module loading but also used by other tools that need to interpret modulefile content.- loadTbl¶
A Lua table defined in
src/lmod.in.luathat acts as a configuration and dispatch target for module loading commands. Entries in the main command dispatch table,lmodCmdA(for user commands like “load”, “add”, etc.), point toloadTblvia theiractionfield. TheloadTblitself contains properties relevant to the load operation, most importantly acmdfield that holds a direct reference to the primary function responsible for handling the load request, which isLoad_Usr()(located insrc/cmdfuncs.lua). It may also contain other metadata likename(for debugging/identification) andcheckMPATH(a boolean indicating ifMODULEPATHneeds to be checked).- LocationT¶
A class (defined in
src/LocationT.lua) that creates a tructured representation of module locations when the module tree is completely N/V or C/N/V and not N/V/V. It is typically initialized with data derived fromModuleA(which itself is built fromDirTree’s scan ofMODULEPATH).LocationT’s primary purpose is to provide an efficient way to search for modules (via itsLocationT:search(name)method) and to helpMNameobjects resolve a given module name string (which might follow various conventions like Name/Version, Category/Name/Version) to its canonical file path and associated properties. It achieves this by abstracting the complexities of different directory layouts found across various module trees, effectively creating a readily searchable map or index.- mcp¶
(Main Control Program) The
mcp(Main Control Program) is the primary stateful object that orchestrates Lmod’s behavior for a given user command. It is an instance of theMainControlclass (defined insrc/MainControl.lua). Themcpobject is typically created usingMainControl.build("mode"), where"mode"(e.g., “load”, “unload”, “spider”, “avail”, “help”) determines its operational context. Key characteristics and roles:State Management: The mode with which
mcpis initialized dictates how subsequent operations are handled. For example, if a modulefile command likeprepend_path()is encountered, themcpobject’s internal logic (based on its mode) will dispatch this to the appropriate underlyingMainControlmethod, such asM.prepend_pathif in “load” mode, orM.remove_pathif in “unload” mode.Method Dispatch: It provides the core methods (like
mcp:load_usr(),mcp:setenv(),mcp:prepend_path()) that are called by higher-level functions (insrc/modfuncs.luaorsrc/cmdfuncs.lua). Thesemcpmethods then delegate to the actual implementation methods (e.g.,M.load_usr(),M.setenv()) within theMainControlclass, tailored to the current mode.Central Orchestration: It ties together various components by holding references or providing access to other key Lmod objects and data structures necessary for the current operation.
The
mcpglobal variable is in the current mode (i.e. load, unload, show, etc).MCPis always in load mode andMCPQis always in quiet mode.- MName¶
An
MName(Module Name) object is Lmod’s primary internal representation of a module. These objects are created from user-provided module name strings (e.g., “gcc/9.3.0”, “tacc”) or from other internal representations.MNameobjects are defined insrc/MName.lua. Key characteristics and roles:Encapsulation: An
MNameobject encapsulates various properties of a module, including its user-specified name, its canonical short name (:sn()), full name (:fullName()), version (:version()), and the resolved path to its modulefile (:fn()).Resolution: It contains the logic to resolve a potentially ambiguous module name string into a specific modulefile on the filesystem. This process involves interacting with other Lmod components like
ModuleA(for collections of modules, mainly when a module tree is N/V/V ), andLocationT(for location indexing and handling different naming schemes like N/V, C/N/V).State & Validation:
MNameobjects can report on the module’s status, such as whether it’s currently loaded (:isloaded()) or if it’s a valid, findable module (:valid()).Operations: They are used extensively throughout Lmod. For example, lists of
MNameobjects are passed to functions likehub:load()andmcp:load_usr()to specify which modules to act upon. Modulefile commands likeprereqorconflictalso operate onMNameobjects.
Instantiation typically occurs via methods like
MName:new(type, name, ...)orMName:buildA(type, argTable).- ModuleA¶
ModuleA(Module Array) is a class, defined insrc/ModuleA.lua, that represents the entire collection of available modules discovered by Lmod from theMODULEPATH. It is typically used as a singleton within Lmod’s operations. Key characteristics and roles:Data Source: It acts as a primary, structured source of information about all known modules. It’s initialized by processing the
MODULEPATHdirectories, usingDirTreeto scan the filesystem and identify modulefiles and their organization.Module Discovery: Provides methods like
:search(name)to find modules, and:defaultT()to get information about default module versions.Information Provider: Supplies data for commands like
module avail(via:build_availA()) and for internal checks, such as determining if a module path follows a Name/Version/Version (:isNVV()) convention.Interaction:
ModuleA’s data is used byLocationTto build its searchable index, andMNameobjects queryModuleA(often viaLocationT) to resolve names to specific modulefile paths and properties.Caching: It can incorporate spider cache information (
spider_cache=true) to speed up discovery if available.
It’s instantiated using
ModuleA:__new({mpathA}, maxdepthT)or more commonly accessed viaModuleA:singleton{spider_cache=...}.- MT¶
(Module Table)
MT(Module Table) is a central Lmod data structure, defined insrc/MT.lua, that represents the current state of the user’s environment in terms of loaded modules. It acts as a live record of which modules are loaded, their properties, and how they were loaded. Key characteristics and roles:State Tracking: It stores detailed information for each loaded module, including its short name (
sn), full name, user-specified name, version, filename (:fn()), status (e.g., “active”, “inactive”, “pending” via:setStatus(),:status(),:have()), load order, and any associated properties.Environment Representation: It maintains the current
MODULEPATHarray (:modulePathA()) and other environment-related settings derived from module operations.Query Interface: Provides numerous methods to query the state of loaded modules, such as listing modules (
:list()), checking if a module is loaded (:have()), retrieving a module’s filename or version.Modification Interface: Offers methods to modify the state, such as adding a module (
:add()), changing its status, or marking it as directly loaded by the user (:userLoad()).Serialization: Can serialize its contents (e.g., via
:serializeTbl()), which is crucial for Lmod to pass its state back to the shell for environment updates (e.g., by settingLOADEDMODULES).Collections: Handles module collections by loading their state from files (
:getMTfromFile()).
The
MTis typically accessed as a singleton object (e.g.,MT:singleton()) or retrieved from the current evaluation context viaframeStk:mt(). It is dynamically updated as modules are loaded and unloaded.For a detailed explanation of its role in state management, see MT: The Module Table.
- myGlobal¶
Refers to the Lua script
src/myGlobals.lua. Its primary purpose is to initialize and make available a wide range of global variables, internal constants, and fundamental settings that govern Lmod’s runtime behavior. Key aspects:Centralized Configuration: It uses the
Cosmicsingleton (cosmic:init{...}) extensively to define and initialize numerousLMOD_*configuration parameters. These parameters can be sourced from compile-time settings (viasedVsubstitution), environment variables (envV), or assigned default values. Examples includeLMOD_TRACING,LMOD_SITE_NAME,LMOD_CONFIG_DIR,LMOD_RC.Internal Constants: Defines essential internal constants like
ModulePath(the string “MODULEPATH”) andLMOD_CACHE_VERSION.Global State: Establishes some baseline global state, such as ensuring
LC_ALLis set to “C” for consistent behavior and initializingExitHookA(an array for functions to be called on exit).Early Initialization: Due to its widespread inclusion, it plays a crucial role in the early setup of Lmod’s operating environment before specific commands are processed.
It serves as a foundational script that provides a consistent and globally accessible set of parameters and constants for the rest of the Lmod codebase.
- runTCLprog()¶
A globally available Lmod function (
_G.runTCLprog) responsible for executing a specified TCL script and returning its output. It is primarily used by:loadModuleFile(): To convert TCL-based modulefiles into Lua code. In this context,runTCLprogis called withtcl2lua.tcl(a TCL script that translates modulecmd TCL syntax to Lua) as the program to run, and the path to the target TCL modulefile plus other necessary arguments.mrc_load.lua: To convert.modulercfiles (which can be TCL based) into Lua. Here,runTCLprogis called withRC2lua.tcl. TherunTCLprogfunction itself has multiple potential backends: it can be a Lua implementation that invokes an externaltclshinterpreter, or if Lmod is compiled with an embedded TCL interpreter (frompkgs/tcl2lua/tcl2lua.corembed/tcl2lua.c), it can be a C function that directly executes the TCL script. Its purpose is to bridge the gap between TCL-based files and Lmod’s Lua core by translating TCL into executable Lua statements.
- sandbox_run()¶
The “sandbox” refers to the controlled execution environment Lmod creates to evaluate the Lua code within modulefiles. This mechanism is primarily implemented in
src/sandbox.lua. Key aspects:Controlled Environment (``sandbox_env``): A specific Lua environment table (
sandbox_env) is constructed. This table explicitly includes a curated list of safe standard Lua library functions (e.g.,pairs,string.format) and all Lmod-provided modulefile API functions (e.g.,prepend_path,load,whatisfromsrc/modfuncs.lua). Functions that could be harmful are generally excluded or replaced by safer Lmod versions.Execution (``sandbox_run``): The Lua code from a modulefile (after being read and potentially converted from TCL by
runTCLprog) is executed using a function, typicallysandbox_run. This function compiles and runs the module code, setting thesandbox_envas the global environment for that code.Purpose: To ensure security (preventing malicious operations), isolation (enforcing a defined API), and robust error handling for modulefile execution.
The
loadModuleFile()function is the primary user ofsandbox_run. A similar mechanism,mrc_sandbox_run(fromsrc/mrc_sandbox.lua), is used for evaluating.modulercfiles.- varT¶
(Variable Table)
varTis Lmod’s internal representation of the environment that is being built or modified as modulefiles are processed. It is not the OS environment itself, but rather a Lua table that Lmod uses to track changes. Key characteristics:Structure:
varTis a Lua table where keys are environment variable names (strings, e.g., “PATH”, “FOO_VERSION”). The values associated with these keys are instances of theVarclass (defined insrc/Var.lua). EachVarobject encapsulates the state and behavior for a single environment variable (e.g., its current value, delimiter for path-like variables, rules for handling duplicates).Access:
varTis typically accessed from the current evaluation context (frame) viaframeStk:varT(), whereframeStkis the singleton instance ofFrameStk.Manipulation: All modifications to the environment dictated by modulefile commands (like
setenv,prepend_path,set_alias) are performed by first obtaining the relevantVarobject fromvarT(creating it if it doesn’t exist viaVar:new(name)) and then calling methods on thatVarobject (e.g.,:set(),:prepend(),:setAlias()). These methods update the internal state of theVarobject withinvarT.Output Generation: After all module commands are processed, Lmod reads the final state of all
Varobjects invarTto generate the shell commands (e.g.,export FOO=bar;,setenv PATH /new/path:$PATH) that will actually modify the user’s shell environment.
For a detailed explanation of its role in state management, see varT: The Variable Table.