Extension:External Data/Lua

External Data defines a Lua function  that fetches external data and returns it as a Lua table, so that wikis that have the Scribunto extension installed can call it to access and display outside data.

Additionally, in backward compatibility mode, 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.
 * If only one parameter  is sufficient for data retrieval (which is often the case due to auto-detection of format or that the parameters are set as a definition of a hidden data source in  ), it can be passed to the Lua function as its only string parameter:.
 * 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.
 * If YAML format is used, an external variable  is set, which contains YAML data keeping the whole structure of the original YAML 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.