Lua API

Configuration

config.set(path, value)

Set a config value under path.

config.get(path)

Get a config value under path. Returns a string.

config.unregister(path, function)

Unregister callback function for the specified path.

config.register(path, function)

Register for notifications on the specified path.

The callback function is called with the changed path as first parameter. The return value is ignored.

HTTP Client Functions

http.request( url[, callback, [[[method, ] content, ] headers]])

Perform HTTP request manually specifying method, content and headers. Method defaults to GET. This function is called by get, post and put.

The response goes to the supplied callback function, which is called with three parameters:

  • responseCode is an integer HTTP response code (200, 404, …)
  • responseBody is a string with the content of the response body
  • responseHeaders is a table mapping string keys to string values

Any return value from the function is ignored.

You can optionally supply request headers as a table mapping string keys to string values.

http.get(url [, callback [, headers]])

Perform HTTP GET for url. See function request for details.

http.post(url [, callback [, content [, headers]]])

Perform HTTP POST for url, optionally sending content. See function request for details.

http.put(url [, callback [, content [, headers]]])

Perform HTTP PUT for url, optionally sending content. See funtion request for details.

HTTP Server Functions

http.listen(url, callback)

Listen for HTTP requests under url. Returns handle which can be passed to stop_listen. The full URL is https://ip-of-phone/api/v1/exec/<url>.

The response goes to the supplied callback function, which is called with three parameters:

  • url is the requested url as a string
  • body is the request body as a string
  • headers is a table mapping string keys to string values

Any return value from the function is ignored.

http.stop_listen(handle)

Stop listening for HTTP requests. Parameter handle must be return value from previous call to listen.

JSON Functions

json.eval(str)

Parse a string and return a Lua table of the contents.

json.insert(object, [index,] value)

Insert a new element into a table representing a JSON array.

Also available on objects returned by functions of this module.

json.object([table])

Create a JSON object, optionally passing content as a lua table.

json.array([table])

Create a JSON array, optionally passing content as a lua table, which must have the semantics of a Lua array (integer keys starting at 1 and consecutive).

json.tostring(obj)

Return string representation of JSON object.

Also available as the __tostring metamethod on objects returned by functions of this module.

Key and Led Functions

On Key presses, a function onKeyUp() is called if present.

Set LED corresponding to the key to the specified color. Allowed values are red, green, yellow and off. blink is a boolean, defaulting to false.

SIP Functions

sip.subscribe(uri [, type [, line]], callback)

Subscribe a resource. Type is an integer describing the Subscription type. Currently only 0 is supported for the dialog package. line is the number of the identity to use for subscription, defaults to the currently selected identity if not specified.

Return value is a userdata representing the subscription which can be used for unsubscribe.

On incoming Notify-messages the callback is called with three parameters:

  • data is the raw content of the notify message
  • url is the subscribed url as a string
  • identity is the number of the identity to use

The return value of the callback is ignored.

sip.unsubscribe(handle)

Unsubscribe a resource previously subscribed with subscribe.

sip.invite(uri [, pickup][, line])

Send an invite, optionally attempting pickup if second parameter is true. line is the number of the identity to use, defaults to the currently selected identity if not specified.

With Release 1.2, hidden and named arguments will be available

sip.invite(uri [, pickup][, line][, hidden])

Parameter hidden if true hides the call from the user.

Supports named arguments uri:string, pickup:bool, hidden:bool, line:string.

E.g.:

sip.invite{uri="sip:570@192.168.0.1",hidden=true}

XML Functions

xml.new(tableOrTag)

Construct new XML object. If tableOrTag is a table, use it (and setup metatable for object-like access). If tableOrTag is a string, use it as the tag.

xml.append(obj, tableOrTag)

Construct new XML object like new and append it to the child elements of obj.

Also available on objects returned by function of this module.

Returns the newly created element.

xml.tag(obj [,tag])

Returns or sets the tag of the object. If tag is nil, returns the current tag, otherwise sets it to tag.

Also available on objects returned by functions of this module.

xml.appendtext(obj, text)

Append text to the xml object obj.

Also available on objects returned by functions of this module.

Returns the object.

xml.find(obj [, tag[, key[, value]]])

Find an element with tag tag and attribute key with value value. tag can be nil or "" to find an element with any tag. If key is not nil or "", the element must have an attribute with this key. If value is not nil, the attribute must have this value.

Also available on objects returned by functions of this module.

Returns the found object or nil if not found.

xml.tostring(obj)

Return string representation of XML object.

Also available as the __tostring metamethod on objects returned by functions of this module.

xml.eval(xmlStr)

Reads xmlStr and transforms each element to a table entry. Behaves similar to xml.eval(xmlstring)

Shared state

Provides a table that can be used from every key.

shared

Table that can contain arbitrary data.