Module:BananesArgs


Exemple

Exemple Résultat
{{#invoke:BananesArgs|hello_world}} Hello, world!
{{#invoke:BananesArgs|hello|Fred}} Hello, Fred!
{{#invoke:BananesArgs|adition|5|3}} 8
{{#invoke:BananesArgs|somme_fruit|bananes=5|pommes=3}} J'ai 5 bananes et 3 pommes
{{#invoke:BananesArgs|total_fruit|Fred|bananes=5|cerises=7}} Fred a : 5 bananes 7 cerises
{{#invoke:BananesArgs|custom_fruit|ananas=10|kiwis=5}} J'ai : 5 kiwis 10 ananas
{{#invoke:BananesArgs|custom_fruit_2|Fred|ananas=10|kiwis=5}} Fred a : 5 kiwis 10 ananas

Voir aussi

Aide:Module


-- Module simple qui démontre comment utiliser les arguments
--[[ Pour en savoir plus sur l'objet Frame, 
 voyez https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual/fr#L.27objet_Frame]]

local p = {}

-- Aucun argument. Pour l'appeler : {{#invoke:BananesArgs|hello_world}}
function p.hello_world()
	return "Hello, world!"
end

-- Un argument. Pour l'appeler : {{#invoke:BananesArgs|hello|Fred}} 
function p.hello(frame)
	local nom = frame.args[1] -- dans cet exemple, args[1] est le mot « Fred » 
	return "Hello, " .. nom .. "!" -- .. nom .. est remplacé par le mot « Fred »
end

-- Deux arguments. Pour l'appeler : {{#invoke:BananesArgs|adition|5|3}}
function p.adition(frame)
	local nomb1 = tonumber(frame.args[1])
	local nomb2 = tonumber(frame.args[2])
	return nomb1 + nomb2
end

-- Argument nommé. Pour l'appeler : {{#invoke:BananesArgs|somme_fruit|bananes=5|pommes=3}}
function p.somme_fruit(frame)
	local nomb_bananes = frame.args.bananes
	local nomb_pommes = frame.args.pommes
	return "J'ai " .. nomb_bananes .. ' bananes et ' .. nomb_pommes .. ' pommes'
end

--[[ Exemple avec des arguments non nommés,  des arguments nommés et des arguments optionnels 
  Pour l'appeler : {{#invoke:BananesArgs|total_fruit|Fred|bananes=5|cerises=7}} ]]
function p.total_fruit(frame)
	local nom = frame.args[1]
	local nomb_bananes = frame.args.bananes
	local nomb_pommes = frame.args.pommes
	local nomb_cerises = frame.args.cerises
	
	local resultat = nom .. ' a :'
	if nomb_bananes then resultat = resultat .. ' ' .. nomb_bananes .. ' bananes' end
	if nomb_pommes then resultat = resultat .. ' ' .. nomb_pommes .. ' pommes' end
	if nomb_cerises then resultat = resultat .. ' ' .. nomb_cerises .. ' cerises' end
	return resultat
end

--[[ Iteration sur args.
 Pour l'appeler : {{#invoke:BananesArgs|custom_fruit|ananas=10|kiwis=5}}]]
function p.custom_fruit(frame)
	local resultat = "J'ai :"
	for nom, valeur in pairs(frame.args) do
		resultat = resultat .. ' ' .. valeur .. ' ' .. nom
	end
	return resultat
end

--[[ Itération sur args avec args obligatoirement distincts 
 Pour l'appeler : {{#invoke:BananesArgs|custom_fruit_2|Fred|ananas=10|kiwis=5}} ]]
function p.custom_fruit_2(frame)
	local nom = frame.args[1]
	local resultat = nom .. ' a :'
	for nom, valeur in pairs(frame.args) do
		if nom ~= 1 then
			resultat = resultat .. ' ' .. valeur .. ' ' .. nom
		end
	end
	return resultat
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.