Zum Inhalt springen

Wikipedia:Lua/Modul/Expr/en

Aus Wikipedia
Vorlagenprogrammierung Diskussionen Lua Test Unterseiten
Modul Deutsch English

Modul: Dokumentation
Weiterleitung der Diskussionsseite fehlt

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

Functions for templates

[Am Gwëntext werkeln]

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

base62
Coding und decoding according toBase62.
  • 1 – figure to be converted
  • 2(optional) D2B for decimal-into-base62; Vorgabe: base62-into-decimal
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

[Am Gwëntext werkeln]
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

[Am Gwëntext werkeln]

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)

[Am Gwëntext werkeln]

A test page illustrates practical use.

Functions for Lua modules (API)

[Am Gwëntext werkeln]

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.

General library; no limitations.

Dependencies

[Am Gwëntext werkeln]

None.