Modul:Homokozó/Pepo41/FrameArgs2Modul

Homokozó/Pepo41/FrameArgs2Modul[mi ez?] • [dokumentáció: mutat, szerkeszt] • [tesztek: létrehozás]

-- EZ A PRÓBAANYAG A FrameArgs2Modul feltöltésére
local arguments = {} -- ide gyűjtjük a tetszőleges számú argumentumot


function val_to_str(v)
    if type(v) == 'string' then
        v = mw.ustring.gsub(v, '\n', '\\n')
        if mw.ustring.match(mw.ustring.gsub(v, '[^\'"]', ''), '^"+$') then
            return "'" .. v .. "'"
        end
        return '"' .. mw.ustring.gsub(v, '"', '\\"' ) .. '"'
    else
        return type(v) == 'table' and table_to_str(v) or tostring(v)
    end
end

function table_key_to_str(k)
    if type(k) == 'string' and mw.ustring.match(k, '^[_%a][_%a%d]*$') then
        return k
    else
        return '[' .. val_to_str(k) .. ']'
    end
end

function table_to_str(tbl)
    local result, done = {}, {}
    for k, v in ipairs(tbl) do
        table.insert(result, val_to_str(v))
        done[k] = true
    end
    for k, v in pairs(tbl) do
        if not done[k] then
            table.insert(result, table_key_to_str(k) .. '=' .. val_to_str(v))
        end
    end
end


function arguments.unpackFrame(frame)
    local i = 0
    local keytab={} 
    for key, value in pairs (frame.args) do   --(frame) do-- nem ad semmit eredményül
        i = i + 1   
        arguments[i] =  value       --frame.args[v] 
    keytab[i] =  key
   end
   local pframe = {}
   local configuracio = {}
   local pframe = frame:getParent()
   local argumentumok = pframe.args -- the arguments passed TO the template, in the wikitext that instantiates the template
   local configuracio = frame.args -- the arguments passed BY the template, in the wikitext of the template itself
   --return configuracio[1], configuracio[2],configuracio["igazítás"], configuracio["szín"], configuracio[5]   
   
   --"Mondottam, ember,küzdj és bízva bízzál "    Madách Imre         bal        kék               123px
   --return unpack(arguments) -- Sajnos nem jönnek sorban az argumentumok. Ez a pairs műve.
    -- return unpack(keytab) 
    -- most kifaggatjuk az argumentumok táblát:
    local i = 0
    local keytab={} 
    for key, value in pairs (argumentumok) do   --(frame) do-- nem ad semmit eredményül
        i = i + 1   
        arguments[i] =  value       --frame.args[v] 
    keytab[i] =  key
   end 
   return unpack(arguments) --Mondottam emberküzdj és bízva bízzálbalrakékPepo41/Luasablon hivása --
                            --  EZ AZ : Erről a (Parentről) lapról hívtam meg a sablont és az invokeval a függvényt.
                            
end
 

return  arguments