Modulo:mchkparametrojn: Malsamoj inter versioj

Enhavo forigita Enhavo aldonita
Taylor 49 (diskuto | kontribuoj)
Nuligis version 695569 de Taylor 49 (Diskuto | kontribuoj)
Etikedo: Malfaro
Taylor 49 (diskuto | kontribuoj)
x
Linio 3:
MODULE "mchkparametrojn" (check parametrojn)
 
"eo.wiktionary.org/wiki/Modulo:mchkparametrojn" <!--2018-Nov-02-->
 
Benefit: performs 2 comparisons in order to check validity
Linio 23:
the lower limit, and less than 64)
- optional "E" string to allow empty parameters
Returned: - string "1" if the parameters are OKaccepted, string "0" if
the parameters supplied to the caller are badrejected, or this
module itself becamebecomes victim of misuze
 
Note that with both WIKI and LUA empty strings and parameters are valid
Linio 31:
however empty parameters are rarely useful, therefore the default
behavior is to disallow them.
 
Note that the result is either "1" "accepted" or "0" "rejected" after this
module has succeeded to run. But there is a third option "module failed to
run" due to not found or timeout for example. The conditional logic in the
calling template must be aware of this.
 
Cannot be used to ensure that ZERO parameters have been submitted,
Linio 38 ⟶ 43:
sed tio estas farebla per simpla "#if"-ordono:
 
<!--enkonduko#
<!--#protekto-->{{#if:<!--o-->{{{1|}}}<!--o-->|<!--then-->{{er
aroplendu|contoh}}<!--o-->[[Kategorio:Erara uzo de con
toh]]<!--o-->}}|<!--endifelse--><!--protekto#kerno-->
#kerno-->"Hello world!" from template "contoh"<!--kerno#
ara uzo de contoh]]<!--o#protekto-->}}<!--endif--><!--protekto#kerno-->"
#fino-->
 
<!--enkonduko#
"<!--#protekto-->{{#ifeqif:<!--o-->{{#invoke:mchkparamet{1|}}}<!--o-->|<!--th
en-->&nbsp;-&nbsp;<!--o-->|<!--else--><!--protekto#
#kerno-->"Hello world!" from template "contoh"<!--kerno#
#protekto-->}}<!--endif--><!--protekto#
#fino-->
 
This module is unbreakable (when called with correct module name
Linio 56 ⟶ 72:
"{{#invoke:mchkparametrojn|ek|0|1}}"
 
"<!--enkonduko#
"<!--#protekto-->{{#ifeq:<!--o-->{{#invoke:mchkparamet
#protekto-->{{#ifeq:<!--o-->{{#invoke:mchkparamet
rojn|ek|1|1}}|<!--equal-->1<!--o-->|<!--th
enrojn|ek|1|2}}<!--o-->|<!--nopequal-->|0<!--elseo-->{{eraroplendu|contoh}}[[Kategorio:Er<!--th
en-->{{eraroplendu|contoh}}<!--o-->[[Kategorio:Erara uzo de con
ara uzo de contoh]]<!--o-->}}<!--endif--><!--protekto#kerno-->"
toh]]<!--o-->}}<!--endif-->{{#ifeq:<!--o-->{{#invoke:mchkparamet
rojn|ek|1|12}}<!--o-->|<!--equal-->1<!--o-->|<!--ththen--><!--protekto#
#kerno-->"Hello world!" from template "contoh"<!--kerno#
#protekto-->}}<!--endif--><!--protekto#
#fino-->"
 
]===]
 
local chkparametrojn = {}
 
function chkparametrojn.ek (frame)
 
local strtmp = "" ; -- temp for decimal conversion
local strret = "0" ; -- output string
Linio 73 ⟶ 96:
local numiter = 0 ; -- index iterating through parameters of the caller
local booemp = false ; -- flag allow empty parameters (default is disallow)
 
if ((frame.args [1]) and (frame.args [2])) then
strtmp = frame.args [1] ; -- lower limit (1 digit)
numlong = mw.ustringstring.len (strtmp) ; -- temp for decimal conversion
if (numlong==1) then
numlowl = mwstring.ustring.codepointbyte (strtmp,1,1) - 48 ; -- may be invalid
if ((numlowl<0) or= lfdec1digit (numlowl>9)) then; -- 255 if invalid
numlowl = 255 ; -- 255 is invalid, note that ZERO would be valid
end--if
end--if
strtmp = frame.args [2] ; -- upper limit (1 or 2 digits)
numlong = mw.ustringstring.len (strtmp) ; -- temp for decimal conversion
if ((numlong==1) or (numlong==2)) then
numuppl = mwstring.ustring.codepointbyte (strtmp,1,1) - 48 ; -- may be invalid
if ((numuppl<0) or= lfdec1digit (numuppl>9)) then; -- 255 if invalid
numuppl = 255 ; -- 255 is invalid, note that ZERO would be valid
end--if
end--if
if (numlong==2) then
numuppm = mwstring.ustring.codepointbyte (strtmp,2,2) - 48 ; -- may be invalid
if ((numuppm<0) or= lfdec1digit (numuppm>9)) then; -- 255 if invalid
if (numuppm==255) then
numuppl = 255 ; -- 255 is invalid, note that ZERO would be valid
else
Linio 104 ⟶ 125:
end--if
end--if
 
if ((numlowl<10) and (numuppl>=1) and (numuppl>=numlowl) and (numuppl<64)) then
while (true) do -- iterate through parameters of the caller
Linio 120 ⟶ 142:
end--if
end--if
strret = strret .. numlowl .. " " .. numuppl .. " "
return strret
 
end--function
 
local function lfdec1digit (num1digit) -- converts 1 digit to decimal
num1digit = num1digit - 48 ; -- may become invalid
if ((num1digit<0) or (num1digit>9)) then
num1digit = 255
end--if
return num1digit
end--function
 
return chkparametrojn