Skip to content
Aaron edited this page Mar 20, 2024 · 1 revision

Lua API

The WordClock application integrates the Lua scripting language for configuration and individual LED animations.

General functions

These functions can be used to manipulate settings or to react on certain events. However, they should be avoided in renderer contexts because of performance and concurrency reasons.

get_settings( path )

Get current settings as JSON string

ParameterTypeRequiredDefaultDescription
pathstringnoemptySub path inside JSON object

Return value:

  • string JSON object

set_settings( json, path )

Set settings given as JSON string

ParameterTypeRequiredDefaultDescription
jsonstringyesJSON object
pathstringnoemptySub path inside target JSON object

Return value:

  • booltrue on success, false on failure

register_signal( pattern, function, before )

Register Lua function as signal sink

ParameterTypeRequiredDefaultDescription
patternstringyesTrigger if signal name matches regular expression
functionstring | functionyesLua function to call (see below)
beforeboolnofalseTrigger function before or after signal sinks in settings.json

Return value:

  • int >= 0 on success (Sink ID, needed for unregister_signal() )
  • int < 0 on failure (probably regular expression error)

Signal function

ParameterTypeDescription
signalstringTriggered signal name
Return valueTypeRequiredDefaultDescription
handledboolnotrueSignal was handled (e.g. makes beep sound on button press)
proceedboolnotrueProceed executing following signal sinks

unregister_signal( id )

Unregister Lua function from signal router

ParameterTypeRequiredDefaultDescription
idintyesSink ID from register_signal()

Return value:

  • booltrue on success, false on failure

trigger_signal( signal )

Trigger signal by name (in the same way as e.g. a button would do)

ParameterTypeRequiredDefaultDescription
signalstringyesSignal name (usually: "source_name,action_name")

Return value:

  • booltrue if signal was handled, false otherwise

beep( msec, freq, volume )

Play beep sound (asynchronous)

ParameterTypeRequiredDefaultDescription
msecintno250Duration (ms)
freqintno2000Frequency (Hz)
volumeintno255Volume (0-255)

pause( msec )

Play beep pause (asynchronous)

ParameterTypeRequiredDefaultDescription
msecintno250Duration (ms)

message( text, count, message_type )

Display message overlay

ParameterTypeRequiredDefaultDescription
textstringyesMessage
countintno1Number of passes (-1 = infinity)
message_typestringnoINFOMessage type (ERROR, WARNING, SUCCESS or INFO)

Return value:

  • int Message ID, needed for stop_message()

stop_message( id )

Stop message overlay

ParameterTypeRequiredDefaultDescription
idintyesMessage ID from message()

get_hwinfo( path )

Get hardware information as JSON string

ParameterTypeRequiredDefaultDescription
pathstringnoemptySub path inside JSON object

Return value:

  • string JSON object

Render functions

These functions can be used to create own renderers, but they are only available inside a LuaRenderer context! They allow setting and getting of LED color values at a given position. The HSV color space specification can be found here.

set_matrix_led_rgb( x, y, r, g, b, a )

Set the RGB color of a matrix LED

ParameterTypeRequiredDefaultDescription
xintyesX position (0-10)
yintyesY position (0-9)
rintyesRed value (0-255)
gintyesGreen value (0-255)
bintyesBlue value (0-255)
aintno255Alpha value (0-255)

set_backlight_led_rgb( x, r, g, b, a )

Set the RGB color of a backlight LED

ParameterTypeRequiredDefaultDescription
xintyesPosition (0-59)
rintyesRed value (0-255)
gintyesGreen value (0-255)
bintyesBlue value (0-255)
aintno255Alpha value (0-255)

set_dots_led_rgb( x, r, g, b, a )

Set the RGB color of a dots LED

ParameterTypeRequiredDefaultDescription
xintyesPosition (0-3)
rintyesRed value (0-255)
gintyesGreen value (0-255)
bintyesBlue value (0-255)
aintno255Alpha value (0-255)

set_matrix_led_hsv( x, y, h, s, v, a )

Set the HSV color of a matrix LED

ParameterTypeRequiredDefaultDescription
xintyesX position (0-10)
yintyesY position (0-9)
hintyesHue (0-255)
sintyesSaturation (0-255)
vintyesValue (0-255)
aintno255Alpha value (0-255)

set_backlight_led_hsv( x, h, s, v, a )

Set the HSV color of a backlight LED

ParameterTypeRequiredDefaultDescription
xintyesPosition (0-59)
hintyesHue (0-255)
sintyesSaturation (0-255)
vintyesValue (0-255)
aintno255Alpha value (0-255)

set_dots_led_hsv( x, h, s, v, a )

Set the HSV color of a dots LED

ParameterTypeRequiredDefaultDescription
xintyesPosition (0-3)
hintyesHue (0-255)
sintyesSaturation (0-255)
vintyesValue (0-255)
aintno255Alpha value (0-255)

get_matrix_led_rgb( x, y )

Get the RGB color of a matrix LED

ParameterTypeRequiredDefaultDescription
xintyesX position (0-10)
yintyesY position (0-9)

Return value:

  • int Red value (0-255)
  • int Green value (0-255)
  • int Blue value (0-255)

get_backlight_led_rgb( x )

Get the RGB color of a backlight LED

ParameterTypeRequiredDefaultDescription
xintyesPosition (0-59)

Return value:

  • int Red value (0-255)
  • int Green value (0-255)
  • int Blue value (0-255)

get_dots_led_rgb( x )

Get the RGB color of a dots LED

ParameterTypeRequiredDefaultDescription
xintyesPosition (0-3)

Return value:

  • int Red value (0-255)
  • int Green value (0-255)
  • int Blue value (0-255)

get_matrix_led_hsv( x, y )

Get the HSV color of a matrix LED

ParameterTypeRequiredDefaultDescription
xintyesX position (0-10)
yintyesY position (0-9)

Return value:

  • int Hue (0-255)
  • int Saturation (0-255)
  • int Value (0-255)

get_backlight_led_hsv( x )

Get the HSV color of a backlight LED

ParameterTypeRequiredDefaultDescription
xintyesPosition (0-59)

Return value:

  • int Hue (0-255)
  • int Saturation (0-255)
  • int Value (0-255)

get_dots_led_hsv( x )

Get the HSV color of a dots LED

ParameterTypeRequiredDefaultDescription
xintyesPosition (0-3)

Return value:

  • int Hue (0-255)
  • int Saturation (0-255)
  • int Value (0-255)

Clone this wiki locally