Jump to content

Module:String: Difference between revisions

366 bytes added ,  11 years ago
Add "rep" function per request by User:קיפודנחש at Wikipedia:Lua requests#Template:Loop and Template:Loop15. Copied from sandbox.
m>WOSlinker
(add nomatch option to str.match)
m>Mr. Stradivarius
(Add "rep" function per request by User:קיפודנחש at Wikipedia:Lua requests#Template:Loop and Template:Loop15. Copied from sandbox.)
Line 381: Line 381:


     return result;
     return result;
end
--[[
    simple function to pipe string.rep to templates.
]]
function str.rep( frame )
    local repetitions = tonumber( frame.args[2] )
    if not repetitions then
        return str._error( 'function rep expects a number as second parameter, received "' .. ( frame.args[2] or '' ) .. '"' )
    end
    return string.rep( frame.args[1] or '', repetitions )
end
end


Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.