Mach Modules Documentation
Lua Module API Documentation
Loading...
Searching...
No Matches
ModuleLoader.lua File Reference

Go to the source code of this file.

Functions

Loader Require (gui_parent_prefix, scr_prefix)
 Load the GUI parent module and versioned screen module for a Mach4 screen.
Loader RequireCommonMCodeModulesAndGlobals (machine_specific_module, optional_aux_module)
 Perform common setup tasks (initialize globals, load modules, etc.).
Loader RequireOEMUserGUIModule (user_module)
 Load and return the OEMUserGUIModule from the profile's Macros/Scripts directory.
Loader RequireUserAuxModule (user_module)
 Load and return the UserAuxModule from the profile's Macros/Scripts directory.

Function Documentation

◆ Require()

Loader Require ( gui_parent_prefix ,
scr_prefix  )

Load the GUI parent module and versioned screen module for a Mach4 screen.

This is the public-facing wrapper around Loader._Require(). It calls _Require() inside a pcall() so that any Lua errors during module loading are caught and displayed to the user via a wxWidgets message box rather than propagating as unhandled exceptions. The versioned screen module name is constructed as "<scr_prefix>V##" where ## is the zero-padded value of the global SCREEN_VERSION (defaulting to 1 if not set). The loaded screen module is attached to the GUI module as GUIModule.screen.

Parameters
gui_parent_prefix(string) The name of the GUI parent module to load (e.g., "MillGUIModule")
scr_prefix(string) The base name of the screen module without the version suffix (e.g., "MillScreen" will load "MillScreenV01" when SCREEN_VERSION is 1)
Returns
(table|nil) The loaded GUI module with the screen module attached as .screen, or nil if an error occurred during loading
Note
Documentation generated by AI on 2026-03-03

◆ RequireCommonMCodeModulesAndGlobals()

Loader RequireCommonMCodeModulesAndGlobals ( machine_specific_module ,
optional_aux_module  )

Perform common setup tasks (initialize globals, load modules, etc.).

Loader.RequireCommonMCodeModulesAndGlobals

This function is invoked by MCodeHeaderFile.mcs in /Profiles/<profile>/Macros/

Parameters
machine_specific_moduleThis is the M code module specific to the machine type, like "MillMCodeModule" or "TurnMCodeModule".
optional_aux_moduleIf not nil, this aux module (code shared between both M code and GUI modules) is loaded as the global aux.

Perform common setup tasks for M-code execution (initialize globals, load modules, etc.)

This function is invoked by MCodeHeaderFile.mcs in /Profiles/<profile>/Macros/ and serves as the primary initialization entry point for all M-code chunk execution. It performs the following major tasks in order:

  1. Initializes global variables: instance counts, directory paths, axis letter arrays, and axis name lookup tables for all active instances.
  2. Extends package.path and package.cpath to include all standard Mach4 module directories, profile-specific script directories, and addon paths.
  3. Loads core modules in sequence: WrapperModule (w), the machine-specific M-code module (m), an optional shared auxiliary module (aux, merged into m), ModbusModule (mb), MotionController, UserMCodeModuleLoader, UserMCodeModule (user), UserAuxModule, LaserMeasureModule (lasermeasure, optional), MotionFilterModule (mf), DataCollector (dt), ToolInfo (optional), lfs, LuaFileQueue (lfq), GCodeTests (optional), and AzureLabelModule (am, conditional on OEM parameter).
  4. Creates MotionController interface objects for each active instance.
  5. Sets MACHINE_DEFAULT_UNITS global after modules are loaded.

If any required module fails to load, an error is logged via w.Log() and a warning dialog is displayed to the user. Optional modules log failures without showing dialogs.

Parameters
machine_specific_module(string) The name of the machine-type M-code module to load as the global m (e.g., "MillMCodeModule" or "TurnMCodeModule")
optional_aux_module(string|nil) If not nil, the name of an auxiliary module to load as the global aux and merge into m. Conflicting keys in m are overridden by aux with a warning logged.
Note
If running in single-instance mode (mcCntlGetInstanceCount() == 1), the global inst is set to the current instance handle for convenience
The global user is always defined after this function completes - either as an empty table (if UserMCodeModule.mcs is not found) or as the loaded UserMCodeModule
Warning
Module load failures for required modules display a warning dialog but do not halt execution. Ensure all required modules are present before calling this function.
Note
Documentation generated by AI on 2026-03-03

◆ RequireOEMUserGUIModule()

Loader RequireOEMUserGUIModule ( user_module )

Load and return the OEMUserGUIModule from the profile's Macros/Scripts directory.

Checks if an OEMUserGUIModule.mcs file exists in the current profile's Macros/Scripts directory. If found, it clears the cached module and attempts to load it via w.pcall(). If loading succeeds, the provided user_module reference is replaced with the loaded OEM module and a success message is logged. If loading fails, an error is logged but no exception is raised. If the file does not exist, the original user_module is returned unchanged.

Parameters
user_module(table) The existing user module table to potentially replace with the loaded OEM module
Returns
(table) The loaded OEMUserGUIModule if found and loaded successfully, otherwise the original user_module
Note
Documentation generated by AI on 2026-03-03

◆ RequireUserAuxModule()

Loader RequireUserAuxModule ( user_module )

Load and return the UserAuxModule from the profile's Macros/Scripts directory.

Checks if a UserAuxModule.mcs file exists in the current profile's Macros/Scripts directory. If found, it clears the cached module and attempts to load it via w.pcall(). If loading succeeds, the provided user_module reference is replaced with the loaded module. If loading fails, an error is logged but no exception is raised. If the file does not exist, the original user_module is returned unchanged.

Parameters
user_module(table) The existing user module table to potentially replace with the loaded aux module
Returns
(table) The loaded UserAuxModule if found and loaded successfully, otherwise the original user_module
Note
Documentation generated by AI on 2026-03-03