![]() |
uvi-script
Musical event scripting with Lua
|
uvi-script is built on the Lua programming language, a lightweight, fast, and embeddable scripting language. Understanding Lua is essential for writing effective uvi-scripts.
This page covers the Lua-specific aspects of uvi-script: which version is used, what libraries are available, and the real-time constraints that shape how you write scripts.
If you're new to Lua or need a reference, we recommend these excellent resources:
These resources are well-written and provide a solid foundation for scripting. Using a simple, widespread, yet powerful scripting language that can be learned online was one of the main motivations for choosing Lua.
What you need to know:
uvi-script uses a sandboxed Lua 5.1 virtual machine with custom extensions designed for real-time audio processing.
Most script code executes with real-time priority to ensure sample-accurate timing and low-latency performance. This places specific constraints on what you can do:
Real-Time Requirements:
Exceptions (Non-Real-Time): These callbacks run with relaxed constraints and can allocate memory:
To maintain real-time safety, uvi-script uses a pre-allocated memory pool for all Lua operations during real-time execution.
Best Practices:
uvi-script provides access to a subset of Lua's standard libraries. Libraries that require operating system access or blocking I/O are not available to maintain real-time safety.
base - Basic Functions
assert, error, pcall, type, tonumber, tostringpairs, ipairs, nextprint, select, unpackrequire - Load Lua modulestable.insert, table.removetable.concattable.sorttable.copy(t) - uvi-script extension: creates a shallow copy of a tablestring - String Operations
string.sub, string.find, string.matchstring.format, string.gsubmath - Mathematical Functions
math.sin, math.cos, math.tan, math.asin, etc.math.abs, math.floor, math.ceil, math.min, math.maxmath.random, math.randomseedmath.pi, math.hugeos - Operating System Facilities
io - File I/O
Third-Party Lua Libraries
uvi-script uses Lua coroutines internally to implement its cooperative threading model. Each event callback (onNote, onRelease, etc.) runs as a separate coroutine that can be suspended using wait, waitBeat, or waitForRelease.
What you need to know:
wait() functionsFor detailed information about threading and timing, see Threading and Timing.