Binding of Isaac: Rebirth Wiki
MannedTooth (discussion | contributions)
Aucun résumé des modifications
(Mauvaise fonction)
 
Ligne 62 : Ligne 62 :
 
function p.toutRogner( f, caracteres, conserverParametresVides )
 
function p.toutRogner( f, caracteres, conserverParametresVides )
 
local g = {}
 
local g = {}
for index, objet in pairs( f ) do
+
for i, j in pairs( f ) do
if type( objet ) == 'string' then
+
if type( j ) == 'string' then
  +
g[i] = mw.text.trim( j ) ~= '' and ( caracteres and mw.text.trim( j, caracteres ) or mw.text.trim( j ) ) or conserverParametresVides and ''
-- Trim
 
if objet ~= nil and mw.text.trim( objet ) ~= '' then
 
if toRemove then
 
g[index] = mw.text.trim( objet, caracteres )
 
else
 
g[index] = mw.text.trim( objet )
 
end
 
end
 
-- Remove empty values ?
 
if mw.text.trim( objet ) == '' and not conserverParametresVides then
 
g[index] = nil
 
end
 
 
else
 
else
 
g[i] = j
-- Do nothing if the content is not a string
 
g[index] = objet
 
 
end
 
end
 
end
 
end

Dernière version du 26 février 2019 à 18:53


local p = {}

function p.obtenirNombreParametres( f )
	local args = p.toutRogner( p.obtenirArgs( f ) )
	local nombreParametres = 0
	if args.numerique then
		local i = 1
		while args[i] do
			nombreParametres = nombreParametres + 1
			i = i + 1
		end
	else
		for i, j in pairs( args ) do
			nombreParametres = nombreParametres + 1
		end
	end
	return nombreParametres
end


function p.rechercher( f )
	local args = p.toutRogner( p.obtenirArgs( f ) )
	if args.index then
		for i, j in pairs( args ) do
			if args.objet == j then
				return i
			end
		end
	else
		local k = 1
		repeat
			if args.objet == args[k] then
				return k
			end
			k = k + 1
		until not args[k]
	end
	return nil
end


-- Obtient les paramètres du modèle et de l'article qui l'utilise
function p.obtenirArgs( f )
	local args = {}
	if f.args then
		-- Ajoute les paramètres du modèle
		for i, j in pairs( f.args ) do
			args[i] = j
		end
		-- Ajoute les paramètres de l'article, écransant ceux du modèle
		for k, l in pairs( f:getParent().args ) do
			args[k] = l
		end
	else
		args = f
	end
	return args
end


-- Exécute mw.text.trim sur toutes les valeurs d'un tableau
function p.toutRogner( f, caracteres, conserverParametresVides )
	local g = {}
	for i, j in pairs( f ) do
		if type( j ) == 'string' then
			g[i] = mw.text.trim( j ) ~= '' and ( caracteres and mw.text.trim( j, caracteres ) or mw.text.trim( j ) ) or conserverParametresVides and ''
		else
			g[i] = j
		end
	end
	return g
end



-- Exécute string.gsub sur tous les indices d'un tableau
function p.igsub( f, motif, repl )
	local g = {}
	for i, j in pairs( f ) do
		g[string.gsub( i, motif, repl )] = j
	end
	return g
end


-- Exécute string.gsub sur toutes les valeurs d'un tableau
function p.gsub( f, motif, repl )
	local g = {}
	for i, j in pairs( f ) do
		if type( j ) == 'string' then
			g[i] = string.gsub( j, motif, repl )
		else
			g[i] = j
		end
	end
	return g
end

return p