Zum Inhalt springen

Wikipedia:Lua/Modul/Expr/en

aus Wikipedia, der freien Enzyklopädie
Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 27. Mai 2013 um 22:41 Uhr durch PerfektesChaos (Diskussion | Beiträge) (Setup). Sie kann sich erheblich von der aktuellen Version unterscheiden.
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Vorlagenprogrammierung Diskussionen Lua Test Unterseiten
Modul Deutsch English

Modul: Dokumentation

Expr – Module with functions for any kind of expression in addition to the functionality offered by #expr parser functions.

Functions for templates

The standard functions are supposed to be used in #invoke and retrieve those parameters. Whitespace ahead and after any content is ignored.

max
Retrieve maximum of a set of figures.
All unnamed parameters are used for extremum calculation.
  • Parameter values may be empty or can contain expressions, which can be evaluated by #expr parser function.
  • Both ASCII minus U+002D and U+2212 − are accepted.
  • Options are available as named parameters:
    • minus – minus sign coding in result; see below
    • zeroBlank=1 – present zero as empty value
The return value is an empty string (nothing), if no parameter at all or only empty values were provided. An error message for invalid #expr might occur as well. Otherwise that is the determined number in the specified formatting.
min
Retrieve minimum in the same way as max.

Direct transclusion in templates

TemplateMax
Like max, but specific to Template:Max – use all parameters of the template around.
TemplateMin
Like min, but specific to Template:Min – use all parameters of the template around.

Unicode minus

The minus sign is treated as follows:

  • On input values they may be used at will.
  • If any input value contains a Unicode minus U+2212, this encoding will be used in the result.
  • Optional minus=1
    Use Unicode minus only for resulting string.
  • Optional minus=-
    Use ASCII hyphen only for resulting string.

A result with Unicode minus is by nature always a string.

Examples (test page)

A test page illustrates practical use.

Functions for Lua modules (API)

All functions documented above may be used via require() in other Modules:

local lucky, Expr = pcall( require, "Module:Expr" )
if lucky then
    Expr = Expr.Expr
else
    -- Error; Expr contains error message
    return "<span class='error'>" .. Expr .. "</span>"
end

Then there is available:

Expr( f, a )
fstring with function name, as above
atable with parameter assignments
  • Values are not supposed to be of string type, but may contain a number itself.
  • Return values may be of type number or could be strings or false.

Usage

General library; no limitations.

Dependencies

None.