Modul:Homokozó/Pepo41/Apa

A Wikipédiából, a szabad enciklopédiából

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

--Version 2014_04_11
local nagyapa =require("Modul:Homokozó/Pepo41/Nagyapa") 

fiuargs={}

local lang = mw.getContentLanguage() 

local ou = ''
function pop(mi,mv1,mv2,mv3,mv4,mv5)  -- idézőjeles rész és 5 bővítmény az ou számára
    	if not mi then return else ou = ou..mi..'\n ' end
      if not mv1 then return else ou = ou..mv1..'\n' end
	if not mv2 then return else ou = ou..mv2..'\n' end
	if not mv3 then return else ou = ou..mv3..'\n' end
	if not mv4 then return else ou = ou..mv4..'\n' end
	if not mv5 then return else ou = ou..mv5..'\n' end
    
end
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 



local function getArg(le,arg,alternativarg, assign ) -- itt eredetileg a frame nem paraméter
    -- Retrieve template argument
    -- Precondition:
    -- 	    le true értékkel jelzi, hogy levágható a paraméter végéről a felesleges vessző és pont
    --     arg     -- string or number; argument identifier
    --     alternativarg -- a paraméternek a másik neve
    --     assign  -- any, optional; default value
    
    local r1 = fiuargs[ arg ] 
    local r2 = nil
    if alternativarg ~= nil then  r2 = fiuargs[ alternativarg ] end
    if r1 == '' or r1 ==nil then r =  r2  else r = r1 end
    if r  == '' then r =  nil  end
    if type( r ) ~= "string" then
        if type( assign ) == nil then
            r = "{{{<" .. arg .. ">}}}"  --ha r nem string tipus, azaz és assign nil érték
        else
            r = assign -- ha r nem string tipus, és assign nem nil
        end
    else -- r típusa string
    	if #r > 1 then -- ha r strint típus és legalább két karaktert tartalmaz
    		local utso_karakter = string.sub(r,-1,-1); 
    		if le then 
    			if utso_karakter == '.' or utso_karakter == ',' then r=string.sub(r,1,-2) end --lecsípjük az utólsó pontot, vagy vesszőt 
    		end
    	end
    end
    return r  
end
function tabledump(tbl, recursive) -- ha recursive==true, akkor a táblán belüli táblákat is kibontja
    if type(tbl) ~= 'table' then
        return '<not a table!>'
    end
    local s = '{ '
    for k,v in pairs(tbl) do
        if type(k) ~= 'number' then 
            k = '"'..k..'"' 
        end
        if type(v) == 'table' then
            if recursive then
                v = table.dump(v, true)
            else
                v = 'table'
            end
        elseif type(v) == 'boolean' then 
               -- no boolean -> string autoconversion in Lua
            if v then
                v = 'true'
            else
                v = 'false'
            end
        end
        s = s .. '['..k..'] = ' .. v .. 'Ð'
    end
    return s .. '} '
end

function _apa(frame)
  
  local  neve, fia = nil
  
  apa_neve= getArg(true,"neve") 
  fia_neve= getArg(true,"fia") 
  
  
 

na=tabledump(nagyapa.args,false)
aa=tabledump(fiuargs,false)
-- az output összeállítása
 pop( 'nagyapaargs=',na)
 pop( 'apaargs=',aa)	
 s=''
 
	if apa_neve then s = s.. apa_neve..' '  end
    if fia_neve then s = s.. fia_neve..' '  end
	if ou  then s = s..ou  end  --ez csak nyomkövetésnél kell, de akkor nagyon
return s
 end 

function run(frame)
	local pframe = frame:getParent()
    fiuargs = pframe.args -- azok a paraméterek, amelyek az apa sablonban vannak
    --config = frame.args -- az #invoke utasításban átadott paraméterek 
    return _apa(frame)
end

local p = {
	run = run, -- semmi mást nem adunk át, csak a futást indító rutint
   -- fiuargs = fiuargs
}

return p