Lua
Key programming with Lua#
The lua-script that runs on a key should define a onKeyUp()
function to define what the key does. It also has access to a key
object to control its led and also text and icon the key shows when displayed.
The key/script can keep a state during the phones activity and has access to a ever growing API to interact with the phone. It contains interfaces to invoke calls, prepare subscriptions, send http requests or register handlers for incoming http and much more.
The following small example has the lua-code directly configured into the key itself. Ususally however it would be part of a template and the key-configuration only points to said template.
Example:
-- simple script used for setting
local state = 0
-- onKeyUp is called when the key is released
function onKeyUp()
state = (state + 1) % 7
if state == 0 then
key:setLed( "off" )
key:setTitle( "off" )
elseif state == 1 then
key:setLed( "red" )
key:setTitle( "red" )
elseif state == 2 then
key:setLed( "red", true )
key:setTitle( "red blinking" )
elseif state == 3 then
key:setLed( "orange" )
key:setTitle( "orange" )
elseif state == 4 then
key:setLed( "orange", true )
key:setTitle( "orange blinking" )
elseif state == 5 then
key:setLed( "green" )
key:setTitle( "green" )
else
key:setLed( "green", true )
key:setTitle( "green blinking" )
end