Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Usien6
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} p.man = function( frame ) return p.ptwiki( frame ) end -- https://en.wikibooks.org/wiki/Lua_Functional_Programming/Functions function where(criteria, array) local result = {} for key, value in pairs(array) do if criteria(key, value) then mw.log("where: criteria(" .. key .. ", " .. value .. ") -> True") table.insert(result, value) -- table.insert(result, key, value) end end return result end function all(criteria, array) local result = true for _, value in pairs(array) do if not criteria(value) then result = false break end end return result end is_string = function(object) return type(object) == "string" end select_arg = function(frame, mandatory, keys, default) local selected_key = "" local selected_keys local selected_keys_count local selected_arg = default local selected_any -- assert( all(is_string, keys), "Erro interno" ) mw.log("select_arg: Procurando parâmetros `" .. table.concat(keys, "`, ou `") .. "`") selected_keys = where(function(keykey, key) return frame.args[key] ~= nil end, keys) selected_keys_count = table.getn(selected_keys) selected_any = ( selected_keys_count > 0 ) mw.log("select_arg: Encontrados " .. selected_keys_count .. ": `" .. table.concat(selected_keys, "`, e `") .. "`") if selected_any then assert(selected_keys_count <= 1, "Conflito de parâmetros: `" .. table.concat(selected_keys, "`, e `") .. "`!" ) selected_key = table.remove(selected_keys, 1) selected_arg = frame.args[selected_key] assert( type(selected_arg) == "string", "Parâmetro `" .. selected_key .. "` não é do tipo 'string'!" ) else assert(not mandatory, "Falta parâmetro: `" .. table.concat(keys, "`, ou `") .. "`!" ) end assert( is_string(selected_arg), "Parâmetro `" .. selected_key .. "` não é do tipo 'string'!" ) return selected_any, selected_key, selected_arg end p.ptwiki = function( frame ) local section = "" local name = "" local system = "" local style = "" mw.log("ptwiki: novo quadro ================") _, _, section = select_arg(frame, true, {1, "seção"}, nil) _, _, name = select_arg(frame, true, {2, "nome"}, nil) _, _, system = select_arg(frame, false, {3, "sistema"}, "7") _, _, style = select_arg(frame, false, {4, "estilo"}, "referência") return "* <b>" .. frame:expandTemplate{ title = "mono", args = {name .. "(" .. section .. ")"}} .. "</b> – " .. system .. " ''(" .. style .. ")''" end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Mono
(
edit
)
Module:Sandbox/Usien6
(
edit
)
Module:Sandbox/Usien6/doc
(
edit
)