Modulo:mchkparametrojn: Malsamoj inter versioj
Enhavo forigita Enhavo aldonita
Nuligis version 695569 de Taylor 49 (Diskuto | kontribuoj) Etikedo: Malfaro |
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
the parameters supplied to the caller are
module itself
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#
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 ⟶ 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▼
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 = {}
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 =
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 ⟶ 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
return num1digit
end--function
return chkparametrojn
|