Lua Functions

 INFORMATION:
 Upgrade to Professional
 View upgrade Instructions

 

 

This page includes all aspects of the included Lua script available in MASSO controllers, including MASSO Exclusive Lua & standard Lua.

 

 

 

M.api

M.api.version.string

Description: Returns the API version as a complete string

Input: none
Returns: string

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.api.version.minor

Description: Returns the minor version number of the API.

Input: none
Returns: integer

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.api.version.patch

Description: Returns the patch version number of the API.

Input: none
Returns: integer

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.api.version.major

Description: Returns the major version number of the API.

Input: none
Returns: integer

Supported in MASSO software v5.13 & API Version: 1.0.0

 

 

 

M.gui

M.gui.action_window_title(s)

Description: Sets the title of the given action button window.

Input: s (string)
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.gui.action_window_show()

Description: Shows the action button window.

Input: none
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.gui.action_window_hide()

Description: Hides action button window.

Input: none
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.gui.action_button_text(i, s)

Description: Sets the text of the given action button inside action button window.

Input: i (action button number), s (string)
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.gui.action_button_text_color(i, hex)

Description: Sets the text color of the given action button inside action button window.

Input: i (button number), hex (color)
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.gui.action_button_color(i, hex)

Description: Sets the background color of the given action button inside action button window.

Input: i (action button number), hex (color)
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.gui.action_button_show(i)

Description: Shows the the given action button inside action button window.

Input: i (action button number)
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.gui.action_button_hide(i)

Description: Hides the the given action button inside action button window.

Input: i (action button number)
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.gui.show_message(t, s)

Description: Displays a message box on the screen with given title and text.

Input: t (string), s (string)
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

 

M.sys

M.sys.get_controller_serial()

Description: Gets the controller serial number.

Input: none
Returns: integer

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.sys.get_machine_units()

Description: Gets the controller working units as setup in the F1-Setup screen.

Input: none
Returns: integer

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.sys.set_optional_stop(x)

Description: Sets the option stop mode.

Input: x (boolean)
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.sys.get_job_counter()

Description: Returns the job counter value.

Input: none
Returns: integer

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.sys.set_job_counter(i)

Description: Sets the job counter value.

Input: i (integer)
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.sys.delay(i)

Description: Causes a delay before continuing the code

Input: i (integer)
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

M.sys.get_job_runtime()

Description: Returns the current job runtime as separate hour, minute, and second values since the job started.
This allows scripts and UIs to easily display the job duration in a human-readable format.

Input: none

Returns: hour (integer), min (integer), sec (integer)

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.sys.send_myworkshop_message(s)

Description: Send a message to myWorkshop.

Input: s (string)
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.sys.get_clock_time()

Description: Gets system time.

Input: none
Returns: table

Supported in MASSO software v5.13 & API Version: 1.0.0

 

 

M.tool

tool.get_current()

Description: Returns the currently active tool number in the spindle.

Input: none

Returns: tool_number (integer) or 0/nil if no tool is loaded

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tool.set_current(tool_number)

Description: Sets the current tool as active in the controller software state.
Use this after a manual or automatic tool change.

Input: tool_number (integer)

Returns: true on success, or nil, err

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tool.get_next()

Description: Returns the next tool that is staged for loading (the tool selected with a T word).

Input: none

Returns: tool_number (integer) or 0/nil if none is staged

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tool.set_next(tool_number)

Description: Sets which tool will be loaded next during a tool change (e.g., M6).

Input: tool_number (integer)

Returns: true on success, or nil, err

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tool.get_slot(tool_number)

Description: Gets the changer slot/pocket number assigned to a tool.

Input: tool_number (integer)

Returns: slot (integer) or nil, err

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tool.set_slot(tool_number, slot)

Description: Assigns or updates the changer slot mapping for a tool.

Input: tool_number (integer), slot (integer)

Returns: true on success, or nil, err

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tool.get_diameter(tool_number)

Description: Returns the nominal diameter of a tool as defined in the tool table.

Input: tool_number (integer)

Returns: diameter_mm (number) or nil, err

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tool.get_name(tool_number)

Description: Gets the name or label assigned to a tool (e.g., “Ø6 Endmill”).

Input: tool_number (integer)

Returns: name (string) or nil, err

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tool.set_name(tool_number, name)

Description: Sets or updates the name of a tool in the tool table.

Input: tool_number (integer), name (string)

Returns: true on success, or nil, err

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tool.get_z_offset(tool_number)

Description: Returns the Z tool length offset for a tool.

Input: tool_number (integer)

Returns: z_offset_mm (number) or nil, err

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tool.set_z_offset(tool_number, z_offset)

Description: Sets the Z tool length offset for a tool.

Input: tool_number (integer), z_offset (number, mm)

Returns: true on success, or nil, err

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tool.get_diameter_wear(tool_number)

Description: Gets the diameter wear/compensation value applied to the tool.

Input: tool_number (integer)

Returns: wear_mm (number) or nil, err

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tool.set_diameter_wear(tool_number, wear)

Description: Sets the diameter wear for a tool, used to fine-tune cutter compensation.

Input: tool_number (integer), wear (number, mm; may be negative)

Returns: true on success, or nil, err

Supported in MASSO software v5.13 & API Version: 1.0.0

 

 

 

 

 

M.printer

M.printer.write(s)

Description: Sends data to printer and returns true if successful else returns false on error.

Input: s (string)
Returns: boolean

Supported in MASSO software v5.13 & API Version: 1.0.0

 

 

 

M.file

M.file.load_gcode_file(s)

Description: Loads a gcode file and returns true if successful else returns false on error.

Input: s (string)
Returns: boolean

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.file.loaded_gcode_file()

Description: Reports the currently loaded G-code file’s name/path so Lua code can reference it in logs, UIs, or tooling.
Input: none
Returns: path_or_name (string) or nil if no file is loaded

Supported in MASSO software v5.13 & API Version: 1.0.0

 

 

 

M.io

M.io.set_output(i, s)

Description: Sets LUA output number state.

Input: i (integer), s (boolean)
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.io.get_output(i)

Description: Gets the LUA output state.

Input: i (integer)
Returns: integer

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.io.get_input(i)

Description: Gets the LUA input state.

Input: i (integer)
Returns: boolean

Supported in MASSO software v5.13 & API Version: 1.0.0

 

M.io.get_adc(i)

Description: Gets the ADC-1 or ADC-2 value.

Input: i (integer)
Returns: integer

Supported in MASSO software v5.13 & API Version: 1.0.0

 

 

 

M.axis

M.axis.get_machine_position()

Description: Gets all the 5 axis machine position.

Input: none
Returns: table

Supported in MASSO software v5.13 & API Version: 1.0.0

 

 

 

string (Standard Lua)

string.lower(s)

Description: Converts all letters in a string to lowercase. Useful for case-insensitive matching or comparisons.
Input: s (string)
Returns: lowercase version of s
 

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.sub(s, i [, j])

Description: Extracts a portion of a string between the given start and end positions.
Input: s (string), i (start index), optional j (end index)
Returns: substring from i to j

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.upper(s)

Description: Converts all letters in a string to uppercase.
Input: s (string)
Returns: uppercase version of s

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.len(s)

Description: Gets the length of the string in bytes.
Input: s (string)
Returns: integer length of the string

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.format(fmt, ...)

Description: Formats text using printf-style syntax. Commonly used for building dynamic strings.

Input: fmt (format string), additional arguments
Returns: formatted string

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.rep(s, n [, sep])

Description: Repeats the given string n times, optionally separated by sep.

Input: s (string), n (repeat count), optional sep (separator)
Returns: repeated string

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.dump(f [, strip])

Description: Serializes a Lua function into bytecode form. Used for saving or transferring functions.

Input: f (function), strip (boolean)
Returns: binary string

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.char(...)

Description: Creates a string from ASCII byte values.

Input: integers (0–255)
Returns: string

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.find(s, pattern [, init [, plain]])

Description: Finds the first occurrence of a substring or pattern in a string.

Input: s (string), pattern (string), optional start index, optional plain flag
Returns: start and end positions, or nil if not found

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.byte(s [, i [, j]])

Description: Returns the numeric codes of characters in a string.

Input: string, optional index range
Returns: integer(s) representing byte values

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.gmatch(s, pattern)

Description: Returns an iterator that produces all pattern matches one by one.

Input: s (string), pattern (string)
Returns: iterator function

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.unpack(fmt, s [, pos])

Description: Reads data from a binary string according to a specified format.

Input: fmt (format string), s (binary string), pos (start position)
Returns: unpacked values, next position

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.packsize(fmt)

Description: Returns how many bytes a format string will use when packing data.

Input: fmt (format string)
Returns: integer size

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.pack(fmt, v1, v2, ...)

Description: Converts values into a packed binary string based on format rules.

Input: fmt (format string), values
Returns: binary string

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.reverse(s)

Description: Returns a new string with characters in reverse order.

Input: s (string)
Returns: reversed string

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.match(s, pattern [, init])

Description: Finds the first substring that matches the pattern and returns captures.

Input: s (string), pattern (string), optional start index
Returns: captures or full match

Supported in MASSO software v5.13 & API Version: 1.0.0

 

string.gsub(s, pattern, repl [, n])

Description: Performs global substitution in a string, replacing matches with the specified value.

Input: s (string), pattern, repl (string/table/function), n (limit)
Returns: modified string, replacements count

Supported in MASSO software v5.13 & API Version: 1.0.0

 

 

 

table (Standard Lua)

table.concat(list [, sep [, i [, j]]])

Description: Concatenates array elements into a single string.

Input: table, optional separator and index range
Returns: string

Supported in MASSO software v5.13 & API Version: 1.0.0

 

table.sort(list [, comp])

Description: Sorts the elements of a table.

Input: array-like table, optional comparison function
Returns: nothing (modifies in place)

Supported in MASSO software v5.13 & API Version: 1.0.0

 

table.insert(list [, pos], value)

Description: Inserts a value into a table at a given position.

Input: table, optional position, value
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

table.move(a1, f, e, t [, a2])

Description: Moves elements between tables or within the same table safely.

Input: source table, start index, end index, target index, optional destination table
Returns: destination table

Supported in MASSO software v5.13 & API Version: 1.0.0

 

table.pack(...)

Description: Packs multiple values into a table and stores the count.

Input: any values
Returns: table with fields 1..n and n

Supported in MASSO software v5.13 & API Version: 1.0.0

 

table.unpack(list [, i [, j]])

Description: Returns table elements as separate values.

Input: table, index range
Returns: multiple values

Supported in MASSO software v5.13 & API Version: 1.0.0

 

table.remove(list [, pos])

Description: Removes and returns an element, shifting others down.

Input: table, optional position
Returns: removed value

Supported in MASSO software v5.13 & API Version: 1.0.0

 

 

 

math (Standard Lua)

math.random([m [, n]])

Description: Returns a random float or integer. Useful for randomness or sampling.

Input: none, m, or m, n
Returns: random number or integer

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.deg(x) / math.rad(x)

Description: Converts between degrees and radians.

Input: radians/degrees
Returns: degrees/radians

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.exp(x) / math.log(x [, base])

Description: Calculates the exponential of a number.

Input: number
Returns: e^x

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.min(...) / math.max(...)

Description: Finds the minimum or maximum of given arguments.

Input: numbers
Returns: smallest or largest value

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.tan(x) / math.sin(x) / math.cos(x)

Description: Standard trigonometric functions.

Input: radians
Returns: trig result

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.sqrt(x)

Description: Returns the square root of a number.

Input: number
Returns: square root

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.floor(x) / math.ceil(x)

Description: Rounds down or up to the nearest integer.

Input: number
Returns: integer (float form)

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.acos(x) / math.asin(x) / math.atan(y [, x])

Description: Inverse trigonometric functions; atan(y, x) returns angle by coordinates.

Input: number(s)
Returns: radians

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.abs(x)

Description: Returns the magnitude of a number.

Input: number
Returns: absolute value

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.type(x)

Description: Determines the numeric type.

Input: number
Returns: "integer", "float", or nil

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.ult(m, n)

Description: Compares integers as unsigned numbers.

Input: integers
Returns: boolean

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.fmod(x, y)

Description: Returns remainder of division, with sign of the dividend.

Input: numbers
Returns: remainder

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.modf(x)

Description: Splits a number into integer and fractional components.

Input: number
Returns: integer part, fractional part

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.tointeger(x)

Description: Converts to integer if possible.

Input: number or string
Returns: integer or nil

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.randomseed(x [, y])

Description: Sets the seed for the random number generator.

Input: seed value(s)
Returns: none

Supported in MASSO software v5.13 & API Version: 1.0.0

 

math.pi, math.huge, math.maxinteger, math.mininteger

Description: Constants for ?, infinity, and integer limits.

Supported in MASSO software v5.13 & API Version: 1.0.0

 

 

 

_G. (Standard Lua)

pairs(t)

Description: Iterates over all key–value pairs in a table.

Input: table
Returns: iterator

Supported in MASSO software v5.13 & API Version: 1.0.0

 

rawget(t, k) / rawset(t, k, v) / rawequal(a, b)

Description: Access or compare table entries without invoking metamethods.

Supported in MASSO software v5.13 & API Version: 1.0.0

 

pcall(f, ...) / xpcall(f, msgh, ...)

Description: Protected call that catches errors instead of throwing them. xpcall uses a custom error handler.

Supported in MASSO software v5.13 & API Version: 1.0.0

 

warn(msg [, level])

Description: Emits a warning message; can be redirected via hooks.

Supported in MASSO software v5.13 & API Version: 1.0.0

 

rawlen(v)

Description: Returns the raw length of a string or table, ignoring metamethods.

Supported in MASSO software v5.13 & API Version: 1.0.0

 

loadfile([filename [, mode [, env]]])

Description: Loads a Lua chunk from file and returns it as a function (not executed).

Supported in MASSO software v5.13 & API Version: 1.0.0

 

load(chunk [, chunkname [, mode [, env]]])

Description: Compiles a Lua chunk from a string or reader function.

Supported in MASSO software v5.13 & API Version: 1.0.0

 

ipairs(t)

Description: Iterates sequentially over array indices 1,2,3... until nil is reached.

Supported in MASSO software v5.13 & API Version: 1.0.0

 

next(t [, k])

Description: Returns the next key–value pair in a table; used internally by pairs().

Supported in MASSO software v5.13 & API Version: 1.0.0

 

assert(v [, message])

Description: Raises an error if v is falsy, otherwise returns v.

Supported in MASSO software v5.13 & API Version: 1.0.0

 

select(index, ...)

Description: Returns arguments starting from position index, or total count if index is "#".

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tonumber(v [, base])

Description: Converts a string or number to numeric type, supporting custom base (2–36).

Supported in MASSO software v5.13 & API Version: 1.0.0

 

collectgarbage([opt [, arg]])

Description: Controls garbage collector. Common options: "collect", "count", "stop", "restart".

Supported in MASSO software v5.13 & API Version: 1.0.0

 

tostring(v)

Description: Converts any value to a human-readable string, using metamethods if available.

Supported in MASSO software v5.13 & API Version: 1.0.0

 

type(v)

Description: Returns the type name of a value as a string.

Supported in MASSO software v5.13 & API Version: 1.0.0

 

setmetatable(t, mt) / getmetatable(v)

Description: Sets or retrieves a value’s metatable; controls behavior like operator overloading.

Supported in MASSO software v5.13 & API Version: 1.0.0

 

error(message [, level])

Description: Raises a runtime error with a message.

Supported in MASSO software v5.13 & API Version: 1.0.0

 

_VERSION

Description: Returns the version of Lua currently running.
Input: none
Returns: string (e.g. "Lua 5.4")

Supported in MASSO software v5.13 & API Version: 1.0.0