Helpo:Lua/Koderoj: Malsamoj inter versioj

Enhavo forigita Enhavo aldonita
Linio 79:
local j = args[3] or pargs[3] or "" -- jaro
</syntaxhighlight>
 
== Analizo ĉu io enhavas jam ligilon ==
Analizas signoĉenon, ĉu ĝi enhavas ligilon:<ref>El la uzantopaĝo [[Uzanto:Tlustulimu/lua#Interesaj kodoj|Uzanto:Tlustulimu/lua]]</ref>
<syntaxhighlight lang="lua" style="margin-left: 2em">
s = v:match( "%[%[[^|%]]*| *([^%]]+) *%]%]" )
if not s then
s = v:match( "%[%[%s*([^%]]+)%s*%]%]" )
end
if not s then
s = v
end
</syntaxhighlight>
* Die erste Klammer heißt übersetzt: Setze ''s'', wenn etwas gefunden wird, das
** "[["
** + allerlei, das weder | noch ] ist
** + Pipe
** + potentielle Leerzeichen
** + MERKEN→''s'': allerlei, das keine ] ist
** + potentielle Leerzeichen
** + "]]"
Rekte en la funkcio:
<syntaxhighlight lang="lua" style="margin-left: 2em">
local s
for k,v in pairs(strings) do
s = v:match( "%[%[[^|%]]*| *([^%]]+) *%]%]" )
if not s then
s = v:match( "%[%[%s*([^%]]+)%s*%]%]" )
end
if not s then
s = v
end
output[k] = '[[Kategorio:' .. cat .. ' ' .. mw.text.trim(s)
if key and key ~= "" then
output[k] = output[k] .. '|' .. key
end
output[k] = output[k] .. ']]'
end
</syntaxhighlight>
En aparta funkcio:
<syntaxhighlight lang="lua" style="margin-left: 2em">
local function f(v, cat, key)
local s
s = v:match( "%[%[[^|%]]*| *([^%]]+) *%]%]" )
if not s then
s = v:match( "%[%[%s*([^%]]+)%s*%]%]" )
end
if not s then
s = v
end
s = '[[Kategorio:' .. cat .. ' ' .. mw.text.trim(s)
if key and key ~= "" then
s = s .. '|' .. key
end
return s .. ']]'
end
 
for k,v in pairs(strings) do
output[k] = f(v, cat, key)
end
</syntaxhighlight>
 
 
== Referencoj ==