Modul:Expr: Unterschied zwischen den Versionen
2022-08-28
(2022-08-20) |
(2022-08-28) |
||
Zeile 1: | Zeile 1: | ||
local Expr = { suite = "Expr", | local Expr = { suite = "Expr", | ||
serial = "2022-08- | serial = "2022-08-28", | ||
item = 54991461 } | item = 54991461 } | ||
--[==[ | --[==[ | ||
Zeile 27: | Zeile 27: | ||
]==] | ]==] | ||
local Failsafe = Expr | local Failsafe = Expr | ||
if mw.site.server:find( ".beta.wmflabs.org", 4, true ) then | |||
require( "Module:No Globals" ) | |||
end | |||
Zeile 43: | Zeile 49: | ||
["',"] = "[',]", | ["',"] = "[',]", | ||
["'."] = "['%.]", | ["'."] = "['%.]", | ||
[" "] | ["U+20"] = " ", | ||
["U+A0"] = mw.ustring.char( 0xA0 ), | ["U+A0"] = mw.ustring.char( 0xA0 ), | ||
["U+202F"] = mw.ustring.char( 0x202F ), | ["U+202F"] = mw.ustring.char( 0x202F ), | ||
Zeile 95: | Zeile 101: | ||
return r | return r | ||
end -- factory() | end -- factory() | ||
local function faculty( analyze ) | |||
-- Test for boolean interpretation | |||
-- Precondition: | |||
-- analyze -- string or boolean or nil | |||
-- Postcondition: | |||
-- returns boolean | |||
local s = type( analyze ) | |||
local r | |||
if s == "string" then | |||
r = mw.text.trim( analyze ) | |||
if r == "" or r == "0" or r == "-" then | |||
r = false | |||
elseif r == "1" then | |||
r = true | |||
else | |||
r = r:lower() | |||
if r == "y" or | |||
r == "yes" or | |||
r == "true" or | |||
r == "on" then | |||
r = true | |||
elseif r == "n" or | |||
r == "no" or | |||
r == "false" or | |||
r == "off" then | |||
r = false | |||
else | |||
if r == "falsch" or r == "nein" then | |||
r = false | |||
else | |||
r = true | |||
end | |||
end | |||
end | |||
elseif s == "boolean" then | |||
r = analyze | |||
elseif s == "nil" then | |||
r = false | |||
else | |||
r = true | |||
end | |||
return r | |||
end -- faculty() | |||
Zeile 172: | Zeile 224: | ||
local r = "" | local r = "" | ||
for k, v in pairs( args ) do | for k, v in pairs( args ) do | ||
if faculty( v ) then | |||
r = "1" | |||
break -- for k, v | |||
end | end | ||
end -- for k, v | end -- for k, v | ||
Zeile 351: | Zeile 396: | ||
Expr.crossTotal = function ( amount ) | Expr.crossTotal = function ( amount ) | ||
-- Calculate sum of digits in integer number | |||
-- Precondition: | |||
-- amount -- string or number, with integer | |||
-- Postcondition: | |||
-- returns number, at least 0 | |||
local r = 0 | local r = 0 | ||
local s = Expr.figure( amount ) | local s = Expr.figure( amount ) | ||
Zeile 361: | Zeile 411: | ||
r = r + tonumber( s:sub( i, i ) ) | r = r + tonumber( s:sub( i, i ) ) | ||
end -- for i | end -- for i | ||
end | end | ||
return r | return r | ||
Zeile 376: | Zeile 424: | ||
-- ask -- string or not, with figure format | -- ask -- string or not, with figure format | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- returns mw.html -- with formatted data, or | ||
-- string -- with "0" if any problem | |||
local r = Expr.figure( amount, ask ) | local r = Expr.figure( amount, ask ) | ||
if r then | if r then | ||
Zeile 419: | Zeile 468: | ||
:addClass( "coordinate-deg-min-sec" ) | :addClass( "coordinate-deg-min-sec" ) | ||
e:wikitext( r ) | e:wikitext( r ) | ||
r = | r = e | ||
else | else | ||
r = "0" | r = "0" | ||
Zeile 434: | Zeile 483: | ||
-- ask -- string, with permitted formatting, defaults to "." | -- ask -- string, with permitted formatting, defaults to "." | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- returns number, or false | ||
-- 2022-08-08 | -- 2022-08-08 | ||
local seek = type( amount ) | local seek = type( amount ) | ||
Zeile 451: | Zeile 500: | ||
else | else | ||
local low, split | local low, split | ||
seek = mw.text.trim( seek ) | |||
if seek == "" then | if seek == "" then | ||
seek = "." | seek = "." | ||
Zeile 599: | Zeile 649: | ||
-- ask -- string or not, with figure format | -- ask -- string or not, with figure format | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- returns number -- with modulo remainder | ||
-- 0 -- if numbers are not available | -- 0 -- if numbers are not available | ||
local qt = Expr.figure( amount, ask ) | local qt = Expr.figure( amount, ask ) | ||
Zeile 625: | Zeile 675: | ||
-- frame -- object, if available | -- frame -- object, if available | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- returns string -- with formatted percentage, terminated by % | ||
-- 0 -- if numbers are not available | -- 0 -- if numbers are not available | ||
local qp = Expr.figure( amount, ask ) | local qp = Expr.figure( amount, ask ) | ||
Zeile 694: | Zeile 744: | ||
-- or wikidata|item|~|@ or false | -- or wikidata|item|~|@ or false | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- returns string -- with queried version/item, also if problem | ||
-- false -- if appropriate | -- false -- if appropriate | ||
-- 2020-08-17 | -- 2020-08-17 | ||
Zeile 787: | Zeile 837: | ||
function p.decimal2minsec( frame ) | function p.decimal2minsec( frame ) | ||
return Expr.decimal2minsec( frame.args[ 1 ], | return tostring( Expr.decimal2minsec( frame.args[ 1 ], | ||
frame.args[ 2 ], | |||
frame.args.parse ) ) | |||
end | end | ||
Zeile 863: | Zeile 913: | ||
end | end | ||
math.randomseed( math.floor( 100000 * os.clock() ) ) | math.randomseed( math.floor( 100000 * os.clock() ) ) | ||
return math.random( 0, n ) | return math.random( 0, n - 1 ) | ||
end | end | ||