|
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.
Lua 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 mathematical simulation or model,
or do something completely different, like create a table of
wind-chill calculations or update a semester course calendar using
the date of first class meeting. Like Python, Lua can be embedded
in other applications. Mira embeds the Lua engine and greatly
expands its capabilities by integrating it with Mira's image
processing algorithms and user interface.
|
NOTE
|
If a complex task only involves repeating a fixed
sequence of user interface commands, the
Mira Project Interface may provide a simpler
alternative to scripting.
|
Script Types
Mira supports scripts that executed directly from
view windows to use displayed data, attach to data in view windows,
or that are independent of displayed data. Scripts may also create
new data and display it in a new view window that becomes part of
the user interface.
-
Launching a script from a view window allows the
script to directly access the image, plot, or grid data displayed
in the window. These scripts are executed from the
Script Manager Pane or by using a menu command. These
scripts require a specific line of code that connects the script to
the view window data. If the script is created by the
Script Manager Pane, Mira automatically inserts this
code into the new script.
-
Scripts executed from a
Script Editor may attach to data displayed in view
windows.
-
Scripts executed from a
Script Editor may not involve view window data.
Documentation
Complete documentation on script functions,
classes, methods, and other features is found in the
Mira Pro x64 Script User's Guide. It
can be viewed from Mira or from the Web:
-
Launch the online
Mira 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.
A Simple Script Example
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 (lua
Table) named f with
Fibonacci numbers and lists the result using the function
list(f).
Mira's
Script Editor assigns colors to specific text
components to distinguish comments, numbers, strings, and language
elements. Comments are in green:
-- Lua:
creates a table of Fibonacci numbers, 1 to n
--
Requires the value of n. Here, set n = 10
n = 10
-- compute
Fibonacci numbers up to n
f = { 1, 2 }
-- start
the table f with elements 1 and 2
for
i = 3,n
do
-- compute
the remaining numbers of the table
f[i]
= f[i-2] + f[i-1]
end
list(f,"Fibonacci
Numbers")
-- list
the table using Mira's generic list()
To executed this script in Mira, first mouse-copy
the listing to the Windows clipboard. In Mira, use theNew > Script Document command and paste into the
document. Click [!] to execute the
script. Note that the list will enclose f with curly
braces because f is a
table.
Overview
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 executed from
inside Mira. Outside of Mira, stand-alone editors that support Lua
syntax highlighting include
Notepad++ and
SciTE , both of which are currently available
at no cost.
Scripts are executed (or "run") by clicking
on the
Script Manager Pane or 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. Executing
compiled code has benefits over interpreted scripts,
including far greater speed and the detection of syntax errors
before execution begins.
Opening a Script
To open a script file for viewing or editing, use
one of the following methods:
-
From an
Image Window,
Plot Window, or
Report Window, select the script in the
Script Manager Pane and click the
button.
-
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].
-
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.
Executing a Script
There are several ways to execute a script. Use the
method that is appropriate:
Saving a Script
Scripts are saved to plain text files with a
lua file extension. Although scripts
can be saved or opened from any folder on the computer, it is
usually advantageous to save scripts in folders with particular
names. For example
Scripts executed from an
Image Window, save in a folder names ImageView_Exec
Plot Window, or
Report Window, scripts should be saved in a folder
with the name ImageView_ <Documents>\...\Mira Pro 8
x64\Scripts Folder
ipts 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:
Creating a New Script
To create a new script, do one of the following.
These actions open an empty Script Editor:
-
From an
Image Window,
Plot Window, or
Report Window, open the
Script Manager Pane and click the button
-
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.
-
NOTE: It is often easier to create a new
script by opening an existing script, modifying it, and saving it
with a new name.
Related Topics
Contents
Script Editor
Script Manager
Script Manager Pane
Editing Script Keywords
Mira Project Interface
Mira Pro x64 8.83 User's Guide, Copyright Ⓒ 2026 Mirametrics, Inc.
All Rights Reserved.
|