Jump to content

Module:Repeat symbols

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Erik Zachte (talk | contribs) at 20:43, 16 September 2014. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

-- use to replace a number by two series of strings (e.g. image links) 
-- first string for tens, second string for single units
-- e.g. invoke with {{#invoke: EZ-Test|repeat_arg_2_3_from_arg_1|52|A|B}} -> "AAAAABB"
-- or try {{#invoke: EZ-Test|repeat_arg_2_3_from_arg_1|52|[[File:Crystal Clear kdm user female vcentered.png|30px]]|[[File:Crystal Clear kdm user male.png|30px]]}}
--   the symbols in the latter case actually give the impression of 5 women, 2 men, 
--   rather than 5* '10 of some metric' + 2 of same metric 

function p.repeat_arg_2_3_from_arg_1 ( frame )
    num_1 = tonumber (frame.args[1]) ;
    str_1 = frame.args[2] ;
    str_2 = frame.args[3] ;

	assert(type(num_1) == "number", "repeat_arg_2_3_from_arg_1 expects a number for first argument") ;
    assert (num_1 >   0, "repeat_arg_2_3_from_arg_1 expects a number > 0 as first argument") ;
    assert (num_1 < 100, "repeat_arg_2_3_from_arg_1 expects a number < 100 as first argument") ;

    num_1 = math.floor (num_1) ;
    mod10 = num_1 % 10 ;
    div10 = math.floor (num_1/10) ; 

    return num_1 .. ' = ' .. div10 .. ' * 10 + ' .. mod10 .. ' -><br>' .. string.rep(str_1,div10) .. string.rep(str_2,mod10) ;
    
end
 
return p