Extension:External Data/Lua

External Data defines Lua functions that match the functionality of its seven "accessor" parser functions, so that wikis that have the Scribunto extension installed can call these functions directly in order to access and display outside data.

The following functions are defined:

The Lua functions accept the same parameters as parser functions, but please note the following:


 * Technically, there is only one parameter; it is known in Lua as a table, and its keys correspond to the parser function parameters.
 * Comma-separated lists like  can be replaced with Lua tables; so that both   and   will work.
 * If XML format is used, an external variable  is set, which contains XML data preserving, with some limitations, the whole structure of the original XML document. It can be referred to in the   argument, and the corresponding internal variable will be a nested Lua table.
 * If JSON format is used, an external variable  is set, which contains JSON data keeping the whole structure of the original JSON document. It can be referred to in the   argument, and the corresponding internal variable will be a nested Lua table.
 * "Valueless" parameters like  can be supplied both as numbered and named:   and   are both valid.
 * Parameters whose name contains a space, like, need to be surrounded with quotes and brackets, like  , unless they are valueless, in which case quotes are enough.

Each Lua function returns two values:


 * 1) A table of external data. Unlike with the parser functions, it will be "row-based", i.e. a numbered array of records with named fields corresponding to external variables. If external data is not fetched, nil will be returned.
 * 2) * If there is only one value for some external variable (it will be in the first record), it will be duplicated as a named field of the returned table, as it is highly likely that it belongs to the rowset as a whole rather than its first row; so that it can be accessed both as  and  ,
 * 3) A numbered table of error messages. If there were no errors, nil will be returned.

Unlike parser functions, external data is only returned to calling Lua module and not stored on the page to be retrieved later by, etc.

Example:

See also the Cargo Lua function, which can be applied to the results returned by   function family to format them Cargo way.