Modulo:mchkparametrojn: Malsamoj inter versioj
Enhavo forigita Enhavo aldonita
Nuligis version 695572 de Taylor 49 (Diskuto | kontribuoj) Etikedo: Malfaro |
ĉu bonas nun ??? |
||
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 16:
Used by templates / Uzata far sxablonoj:
- many / multaj
Required submodules / Bezonataj submoduloj:
- none / neniuj
Incoming: - 2 or 3 anonymous parameters
Linio 23 ⟶ 26:
the lower limit, and less than 64)
- optional "E" string to allow empty parameters
Returned: - string "1" if the parameters are
the parameters supplied to the caller are
module itself
Note that with both WIKI and LUA empty strings and parameters are valid
Linio 31 ⟶ 34:
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 ⟶ 46:
sed tio estas farebla per simpla "#if"-ordono:
<!--enkonduko#
aroplendu|contoh}}<!--o-->[[Kategorio:Erara uzo de con
toh]]<!--o-->
#kerno-->"Hello world!" from template "contoh"<!--kerno#
#fino-->
<!--enkonduko#
en--> - <!--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 ⟶ 75:
"{{#invoke:mchkparametrojn|ek|0|1}}"
"<!--enkonduko#
▲"<!--#protekto-->{{#ifeq:<!--o-->{{#invoke:mchkparamet
#protekto-->{{#ifeq:<!--o-->{{#invoke:mchkparamet
rojn|ek|1|1}}|<!--equal-->1<!--o-->|<!--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
#kerno-->"Hello world!" from template "contoh"<!--kerno#
#protekto-->}}<!--endif--><!--protekto#
#fino-->"
]===]
local chkparametrojn = {}
local function lfdec1digit (num1digit) -- converts 1 digit to decimal
num1digit = num1digit - 48 ; -- may become invalid
if ((num1digit<0) or (num1digit>9)) then
num1digit = 255 ;
return num1digit
end--function
function chkparametrojn.ek (frame)
local strtmp = "" ; -- temp for decimal conversion
local strret = "0" ; -- output string preset to "rejected"
local numlong = 0 ; -- temp for decimal conversion (length of parameter)
local numuppm = 0 ; -- temp for decimal conversion (no need to preset)▼
local numuppl = 255 ; -- upper limit (preset to invalid)▼
local numlowl = 255 ; -- lower limit (preset to invalid)
▲ local numuppl = 255 ; -- upper limit (preset to invalid)
▲ local numuppm = 0 ; -- temp for decimal conversion (no need to preset)
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 =
if (numlong==1) then
numlowl =
▲ end--if
end--if
strtmp = frame.args [2] ; -- upper limit (1 or 2 digits)
numlong =
if ((numlong==1) or (numlong==2)) then
numuppl =
end--if
if (numlong==2) then
numuppm =
if (numuppm==255) then
numuppl = 255 ; -- 255 is invalid, note that ZERO would be valid
else
Linio 104 ⟶ 136:
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 117 ⟶ 150:
end--while
if ((numiter>=numlowl) and (numiter<=numuppl)) then
strret = "1" ; -- set output string to report
end--if
end--if
return strret
end--function
return chkparametrojn
|