|
Mach Modules Documentation
Lua Module API Documentation
|
Go to the source code of this file.
Functions | |
| CommonMCodeModule | GetInstance (func_name) |
| Get a tagged Mach4 instance handle for the current macro instance. | |
| CommonMCodeModule | InitializeScrAPI () |
| Initialize the screen IPC API for M-code to screen communication. | |
| CommonMCodeModule | InvokeMacro (macro_name,...) |
| Entry point for typical macros with no pre/post/finally behavior. | |
| CommonMCodeModule | InvokeMacroEx (macro_name, opt_behavior,...) |
| Invoke an M code (macro) in the standard way, including error checking, alarms, etc. | |
| CommonMCodeModule GetInstance | ( | func_name | ) |
Get a tagged Mach4 instance handle for the current macro instance.
Returns a tagged instance handle for the current macro instance (MINSTANCE). If func_name is nil, returns the raw MINSTANCE value directly. Otherwise, looks up a cached tagged handle in the instance handle cache (CommonMCodeModule.__ihc). If no cached handle exists for the given function name, creates a new tagged instance handle via mc.mcGetInstance() with a descriptive name and stores it in the cache to avoid creating redundant tagged handles.
| func_name | (string|nil) The function name to embed in the tagged instance handle for diagnostic log identification. If nil, returns the raw instance number |
References func_name().
| CommonMCodeModule InitializeScrAPI | ( | ) |
Initialize the screen IPC API for M-code to screen communication.
Loads the 'screenipc' Lua module and initializes the IPC connection to the screen process via a named pipe at 'pipe://localhost:48500'. If the scr global is already initialized, this function is a no-op. Displays a wxMessageBox error dialog if the IPC initialization fails.
| CommonMCodeModule InvokeMacro | ( | macro_name | , |
| ... ) |
Entry point for typical macros with no pre/post/finally behavior.
CommonMCodeModule.InvokeMacro
This facility is here primarily for uniformity of error handling and reporting.
Examples m.InvokeMacro('m19',hVars,S)
m.InvokeMacro('m3')
Entry point for typical macros with no pre/post/finally behavior
Provides a simplified interface for invoking M-code macros that do not require pre/post/finally hook callbacks. Delegates directly to m.InvokeMacroEx() with nil opt_behavior, preserving all standard hook execution and error handling behavior.
| macro_name | (string) The precise name of the macro to invoke |
| ... | (any) All arguments to pass verbatim to the underlying macro function |
| CommonMCodeModule InvokeMacroEx | ( | macro_name | , |
| opt_behavior | , | ||
| ... ) |
Invoke an M code (macro) in the standard way, including error checking, alarms, etc.
CommonMCodeModule.InvokeMacroEx
Macros do not really return anything. They do something. When they fail, they should error(). This function is departing from the "a,b,c" return value convention employed in earlier code.
Because this function is intended as the main entry point for common macro behavior, it will never (deliberately) create an error. It will raise alarms if anything fails.
The pre/post/finally hooks are intended to provide a (machine type-specific) macro with a way to slightly customize its behavior from the default implementation. Normal modifications of this behavior could (and probably should) be implemented as a UserMCodeModule hook.
This function will invoke common hooks in the same way that the macros (implemented here, e.g.) would do it. Thus, new macro implementations should never need to run the general hooks (e.g. user.Userm3, user.m3, m.Machinem3) except for specific ones that only the macro implementation knows how/when to use (e.g. GUI/CycleStartFinal).
There are numerous macros that call m.RunHooks() or attempt to manually run a user hook. We need to ensure that this facility doesn't result in the macro being invoked twice every time the macro is run.
Maintain a separate, "secret namespace" for the real hooks that this script will invoke. The "formal namespace" is how the hooks are defined in their respective source code.
| macro_name | the (precise) name of the macro to invoke |
| opt_behavior | (optional) a table of information used to govern exceptional behavior e.g. cleanup action, other special behavior These hooks should error() if something goes wrong. The return value is meaningful, but it is not used to make decisions. 'pre': called before the macro is invoked ('pre_args' passed as the only argument) If this fails (return false or error()), the macro call and 'post' will not happen, but 'finally' will. 'post': called after the macro returns, but NOT if earlier steps fail 'finally': called after the macro returns, EVEN IF earlier steps fail |
| ... | all the arguments given to the macro entry point that should be passed verbatim to the underlying macro function |
Examples
return m.InvokeMacro('m19',hVars,S)
– Invoke the macro implementation and invoke a "finally" function (always invoked, even if the macro fails) return m.InvokeMacroEx('LubeSystem', { ["finally"] = function() w.SetOEMRegValueString("LubeSystemInCycle", "false") if w.IsOEMParamSigMapped("LubeOutputName") then w.SetOEMParamSig("LubeOutputName", false) end end }, ...)
Invoke an M-code macro in the standard way with full hook and error handling
This is the primary entry point for executing common macro behavior. It orchestrates the complete macro invocation sequence in the following order:
This function is designed to never itself raise an error; all failures are communicated via w.AlarmError(). The opt_behavior hooks should use error() to signal failure.
| macro_name | (string) The precise name of the macro to invoke |
| opt_behavior | (table|nil) Optional table controlling exceptional behavior with keys:
|
| ... | (any) All arguments to pass verbatim to the underlying macro function |