Version 1.4#
Note: not everything was documented back then, some 1.6-Functions might exist as well. Maybe with less parameters.
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.
DEBUG Functions#
debug.getLoadableLibs()#
Returns a list of all Libraries that can be called into any LuaScript using require("[libname]").
In 1.4 this only lists the modules of the luaLibraries. Since 1.6 it also provides the 'backed-in' libraries we've added into the firmware (currently a subset of the penlight-library).
debug.log(message, level)#
Post a log-message into androids logcat-system. Logcat-Category (e.g. to filter for) will be "LuaScript".
The message-parameter can be any non-empty-string.
The level-parameter must be a string that starts with either:
-
'e' (error)
-
'w' (warning)
-
'i' (info) -> might not be logged, see warning below
-
'd' (debug) -> might not be logged, see warning below
-
'v' (verbose) -> default when level doesn't start with one of these characters - usually never included in log, see note below
Info
Since 1.6 there is a setting that limits logs to only show ERRORs and WARNINGs. To enable logs up to DEBUG, you need to set Access -> Extended Logging.
Info
VERBOSE logs usually do not show up, unless you use androids adb-tool to connect to your phone and increase the log sensitivity with `adb shell setprop log.tag.LuaScript VERBOSE
SYSTEM Functions#
system.toast( text:string )#
Displays the provided text for a few seconds.
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.
key.setLed(color [, blink])#
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]) in 1.0#
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.
sip.invite(uri [, pickup][, line][, hidden]) since 1.2#
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)