Modulo:mchkparametrojn: Malsamoj inter versioj

Enhavo forigita Enhavo aldonita
Taylor 49 (diskuto | kontribuoj)
update
Taylor 49 (diskuto | kontribuoj)
Nuligis version 695569 de Taylor 49 (Diskuto | kontribuoj)
Etikedo: Malfaro
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 acceptedOK, string "0" if
the parameters supplied to the caller are rejectedbad, or this
module itself becomesbecame 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 43 ⟶ 38:
sed tio estas farebla per simpla "#if"-ordono:
 
<!--#protekto-->{{#if:<!--o-->{{{1|}}}<!--o-->|<!--then-->{{er
<!--enkonduko#
aroplendu|contoh}}<!--o-->[[Kategorio:Erara uzo de con
#protekto-->{{#if:<!--o-->{{{1|}}}<!--o-->|<!--then-->{{er
toh]]<!--o-->|}}<!--elseendif--><!--protekto#kerno-->
aroplendu|contoh}}<!--o-->[[Kategorio:Erara uzo de con
toh]]<!--o-->|<!--else--><!--protekto#
#kerno-->"Hello world!" from template "contoh"<!--kerno#
#protekto-->}}<!--endif--><!--protekto#
#fino-->
 
<!--enkonduko#
#protekto-->{{#if:<!--o-->{{{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 72 ⟶ 56:
"{{#invoke:mchkparametrojn|ek|0|1}}"
 
"<!--#protekto-->{{#ififeq:<!--o-->{{{1|}}}<!--o-->|<!--th#invoke:mchkparamet
"<!--enkonduko#
rojn|ek|1|21}}<!--o-->|<!--equal-->1<!--o-->|<!--then--><!--protekto#th
#protekto-->{{#ifeq:<!--o-->{{#invoke:mchkparamet
rojn|ek|1|2}}<!--oen-->|<!--equalnop-->0|<!--oelse-->{{eraroplendu|<!--thcontoh}}[[Kategorio:Er
#protektoara uzo de contoh]]<!--o-->}}<!--endif--><!--protekto#kerno-->"
en-->{{eraroplendu|contoh}}<!--o-->[[Kategorio:Erara uzo de con
toh]]<!--o-->}}<!--endif-->{{#ifeq:<!--o-->{{#invoke:mchkparamet
rojn|ek|1|2}}<!--o-->|<!--equal-->1<!--o-->|<!--then--><!--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 96 ⟶ 73:
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 = stringmw.ustring.len (strtmp) ; -- temp for decimal conversion
if (numlong==1) then
numlowl = stringmw.byteustring.codepoint (strtmp,1,1) - 48 ; -- may be invalid
numlowl = lfdec1digitif ((numlowl<0) ;or -- 255 if(numlowl>9)) invalidthen
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 = stringmw.ustring.len (strtmp) ; -- temp for decimal conversion
if ((numlong==1) or (numlong==2)) then
numuppl = stringmw.byteustring.codepoint (strtmp,1,1) - 48 ; -- may be invalid
numuppl = lfdec1digitif ((numuppl<0) ;or -- 255 if(numuppl>9)) invalidthen
numuppl = 255 ; -- 255 is invalid, note that ZERO would be valid
end--if
end--if
if (numlong==2) then
numuppm = stringmw.byteustring.codepoint (strtmp,2,2) - 48 ; -- may be invalid
numuppm = lfdec1digitif ((numuppm<0) ;or -- 255 if(numuppm>9)) invalidthen
if (numuppm==255) then
numuppl = 255 ; -- 255 is invalid, note that ZERO would be valid
else
Linio 125 ⟶ 104:
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 142 ⟶ 120:
end--if
end--if
 
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