Mira Scripting Interface
The Mira Pro Script module extends Mira's capabilities for image processing and general computational applications by adding classes and functions to the Lua programming language (see https://lua.org). Lua is a modern high-level language with a syntax having many similarities to Python. It is widely used by the gaming industry and as a high-level interface for products such as Adobe Photoshop.
The Mira Scripting Interface provides a complete facility for extending Mira's image and data processing capabilities and for other computing tasks that do not involve Mira commands. For example, a script might be used to automate a complex image processing procedure, evaluate prototypes for different processing algorithms, create a 2-D mathematical simulation or model, or do something completely different, like update a semester course calendar based on the date of first class meeting. Like Python, Lua includes an interactive command-line interpreter and can be embedded in other applications. However, Mira embeds the Lua engine and thus greatly expands its capabilities by connecting to Mira's image processing functionality and user interface. When automating a sequence of user interface commands, a simpler alternative to scripting may be to use the Mira Project Interface.
Complete documentation on script functions, classes, methods, and other features is found in theMira Pro x64 Script User's Guide. It can be viewed from Mira or from the Web:
Launch the onlineMira Pro x64 Script User's Guide in a browser on any computing platform.
Open the Windows-based Mira Pro x64 Script User's Guide from its desktop icon or the Help menu in Mira Pro x64.
Below is a basic script that computes a short sequence of Fibonacci Numbers. It does not use any of Mira's processing functions or user interface features other than listing the results in a Text Editor window. This script fills an array named f and lists the results using the compact function list(f). Although this script is shown as plain text, Mira's Script Editor assigns colors to specific text components to distinguish comments, numbers, strings, and language elements:
-- Lua: Fibonacci series 1 to n
-- Requires the value of n. Here, set n = 10
n = 10
f = { 1, 2 } -- start with 1, 2
for i = 3,n do
f[i] = f[i-2] + f[i-1]
end
list(f)
To run this script in Mira, first mouse-copy it to the clipboard. In Mira, use theNew > Script Document command and paste into the document. Click [!] to execute the script.
Mira scripts are stored in plain text files having a .lua file type extension which Mira opens as a Lua script. For viewing, creating, and modifying scripts, Mira provides a Script Editor, a syntax highlighting text editor that adds color and other markup to highlight various elements of the script. This effect can be viewed by comparing the same script file in the Mira Script Editor with a plain text editor like Notepad. Scripts can also be created and edited outside Mira using Notepad or another editor, but must be run (or executed) from inside Mira. External editors that support syntax highlighting for the Lua language include Notepad++ and SciTE , both of which are currently available at no cost.
Scripts are run (or executed) using the [!] button on the Script Editor window's toolbar and the Main Toolbar. Mira feeds the script text to the Lua engine which then compiles the text to byte code and executes it. Running compiled code has benefits over interpreted scripts, including far greater speed and the detection of syntax errors before execution begins.
To open a script from a file, do one of the following. These actions load the existing script into a Script Editor:
Use the File > Open command (Ctrl+O) and choose Lua Script File (*.lua) from the File Types drop box. Select the script file and click [Open].
Click the down-arrow on the button on the main toolbar, and select [Script Manager]. In the Script Manager dialog, select a script and click the [Open] button.
Select a .lua file from the MRU (Most Recently Used) files list at the bottom of the File menu.
Drag a .lua file from Windows Explorer and drop it onto the Mira window.
There are several ways to run a script. Use the method that is appropriate:
From the Main Toolbar, click .
From the Script Editor, click .
From the Script Manager, click [Run].
Directly from one of several Mira window types, including Image Windows, Plot Windows, Grid Windows, and Measurement Panes that contain a Grid Control.
Scripts are saved to text files with a lua file extension. You can choose to save
scripts in the ...\Mira Pro 8 x64\Scripts
folder tree or
anywhere in your file system. If you choose To save them outside
the ...\Mira Pro 8 x64\Scripts
folder tree, then they
will not be accessible from the Script Manager. To save a script,
use one of the following methods:
To Same file: Use the File > Save command (Ctrl+S ) or the button.
To Different file: Use the File > Save As command.
To create a new script, do one of the following. These actions open an empty Script Editor:
Execute the File > New command (Ctrl+N) and select Script Document as the new document type. Double click the document type or click [OK] to create the new script document.
Click the down-arrow on the button on the main toolbar, and select [Script Manager]. In the Script Manager dialog, click [New].
NOTE: It is often easier to create a new script by opening an existing script, modifying it, and saving it with a new name.
Mira Pro x64 8.72 User's Guide, Copyright Ⓒ 2024 Mirametrics, Inc.
All Rights Reserved.