System
System-level APIs and environment constraints.
Listener
Callback that observes changes on an object. Supports two calling conventions:
Usage
-- Simple callback
property:addListener(function()
print("Value changed to", property.value)
end)
-- Bound object callback
property:addListener(self, function(obj)
print("Changed on", obj)
end)
Output
Output<T> is a type alias (Output<T> = T) that marks a field as an output exposed to the Rive runtime. The runtime reads output values each frame.
Usage
export type MyScript = {
result: Output<number>,
label: Output<string>,
}
function advance(self: MyScript, seconds: number): boolean
self.result = math.sin(seconds) -- Runtime reads this value
self.label = "Hello"
return true
end
EnumValues
Collection of enum values. Supports length operator and indexed access.
Operators
Length (#)
Returns the number of enum values.
local count = #enumValues
Index ([])
Access individual enum values by index.
local firstOption = enumValues[1]
Example
local enum = vm:getEnum("status")
local values = enum:values()
for i = 1, #values do
print(i, values[i])
end
See Also: PropertyEnum
Sandbox Limitations
Not available in Rive's Luau environment:
| Library | Status |
|---|---|
io | Not available |
os | Partial (os.clock(), os.time(), os.difftime() only) |
debug | Not available |
package | Not available |
loadfile, dofile, loadstring | Not available |
The __gc metamethod is also disabled.
late()
Deferred initialization marker for script fields. Use in factory return tables for fields that will be assigned later (e.g., in init()).
declare function late(): any
Example
return function(): Node<MyScript>
return {
init = init,
advance = advance,
myPath = late(), -- Will be assigned in init()
myPaint = late(),
}
end
Audio
Global API for audio playback. Used with AudioSource assets.
Methods
Audio.time()
Returns the current audio system time in seconds.
Audio.time(): number
Audio.sampleRate()
Returns the audio sample rate.
Audio.sampleRate(): number
Audio.timeFrame()
Returns the current audio system time in frames.
Audio.timeFrame(): number
Audio.play(source)
Plays an audio source immediately. Returns an AudioSound for controlling playback.
Audio.play(source: AudioSource): AudioSound
Audio.playAtTime(source, time)
Schedules playback at a specific audio time.
Audio.playAtTime(source: AudioSource, time: number): AudioSound
Audio.playInTime(source, delay)
Schedules playback after a delay in seconds.
Audio.playInTime(source: AudioSource, delay: number): AudioSound
Audio.playAtFrame(source, frame)
Schedules playback at a specific frame.
Audio.playAtFrame(source: AudioSource, frame: number): AudioSound
Audio.playInFrame(source, frames)
Schedules playback after a delay in frames.
Audio.playInFrame(source: AudioSource, frames: number): AudioSound
Example
function init(self: MyScript, context: Context): boolean
local source = context:audio("click_sound")
if source then
local sound = Audio.play(source)
sound.volume = 0.8
end
return true
end
See Also: AudioSource, AudioSound, Context
Next Steps
- Continue to Quick Reference
- Review key terms in Glossary