Différences entre les pages « Module:TableBuilder » et « Modèle:Doc modèle/Preload »

De Les Mots de l'agronomie
(Différence entre les pages)
imported>Jacques Ducloy
m (1 révision importée)
 
imported>Jacques Ducloy
(Nouvelle page : <includeonly><no</includeonly><includeonly>include>{{documentation modèle vue directement}}</no</includeonly><includeonly>include> ==Utilisation== : Description du rôle de ce mod...)
 
Ligne 1 : Ligne 1 :
--Module appliquant aux fonctions de la librairie Table une inteface fluide.
+
<includeonly><no</includeonly><includeonly>include>{{documentation modèle vue directement}}</no</includeonly><includeonly>include>
  
local meta = {
+
==Utilisation==
 +
: Description du rôle de ce modèle à compléter.
  
    insert = function ( t, ... )
+
==Syntaxe==
        table.insert( t, ... )
+
* <code><nowiki>{{</nowiki>{{sub</includeonly><includeonly>st:BASEPAGENAME}}<nowiki>|paramètre1|nom1param=valeur1}}</nowiki></code>
        return t
 
    end,
 
   
 
    remove = function ( t, ... )
 
        table.remove( t, ... )
 
        return t
 
    end,
 
   
 
    sort = function ( t, ... )
 
        table.sort( t, ... )
 
        return t
 
    end,
 
   
 
    maxn = function ( t )
 
        return table.maxn( t )
 
    end,
 
   
 
    concat = function ( t, ... )
 
        return table.concat( t, ... )
 
    end,
 
   
 
    minsert = function( t, ... )
 
        local sel
 
        for i = 1, select( '#', ... ) do
 
            sel = select( i, ... )
 
            if sel then
 
                table.insert( t, sel )
 
            end
 
        end
 
        return t
 
    end,
 
   
 
    tinsert = function( t, tab, first, last )
 
        if type( tab ) == 'table' then
 
            for i = ( tonumber( first ) or 1 ), ( tonumber( last ) or #tab ) do
 
                table.insert( t, tab[i] )
 
            end
 
        end
 
        return t
 
    end,
 
}  
 
  
meta.__index = function ( t, key )  
+
==Paramètres==
    local metafunc = meta[key]
+
* '''1''' = ''paramètre1'' – description (obligatoire/optionnel, par défaut ''valeur'')
    if type( metafunc ) == 'function' then
+
* '''nom1param''' = ''valeur1'' – description (obligatoire/optionnel, par défaut ''valeur'')
        return function ( ... ) return metafunc( t, ... ) end
 
    end
 
end
 
       
 
-- fin des fonctions de la meta-table
 
  
 +
==Exemple==
 +
* <code><nowiki>{{</nowiki>{{sub</includeonly><includeonly>st:BASEPAGENAME}}<nowiki>|paramètre1|nom1param=valeur1}}</nowiki></code>
 +
{{{{sub</includeonly><includeonly>st:BASEPAGENAME}}|paramètre1|nom1param=valeur1}}
  
local TableBuilder = {
+
<include</includeonly><includeonly>only>
    new = function( ... )
+
<!-- Catégories pour le [[Modèle:{{sub</includeonly><includeonly>st:BASEPAGENAME}}]]-->
        local t = { ... }
+
{{DEFAULTSORT:{{sub</includeonly><includeonly>st:BASEPAGENAME}}}}<!-- à remplacer si le nom du modèle a des accents -->
        setmetatable( t, meta )
+
[[Catégorie:Espace Modèle<!-- RECHERCHEZ UNE SOUS-CATEGORIE APPROPRIÉE -->]]
        return t
 
    end,
 
   
 
    set = function( t )
 
        if type( t ) == 'table' then
 
            setmetatable( t, meta )
 
        end
 
        return t
 
    end,
 
  
    clone = function ( t )
+
<!-- Interwikis pour le [[Modèle:{{sub</includeonly><includeonly>st:BASEPAGENAME}}]]-->
        local tableRefs = { }
+
[[en:Template:{{sub</includeonly><includeonly>st:BASEPAGENAME}}]]
        local function recursiveClone( val )
 
            if type( val ) == 'table' then
 
                -- Encode circular references correctly
 
                if tableRefs[val] ~= nil then
 
                    return tableRefs[val]
 
                end
 
   
 
                local retVal = { }
 
                tableRefs[val] = setmetatable( retVal, meta )
 
   
 
                for key, elt in pairs( val ) do
 
                    retVal[key] = recursiveClone( elt )
 
                end
 
                return retVal
 
            else
 
                return val
 
            end
 
        end
 
        return recursiveClone( t )
 
    end,
 
}
 
  
return TableBuilder
+
</include</includeonly><includeonly>only></includeonly>

Version du 23 juillet 2009 à 15:43