יחידה:String: הבדלים בין גרסאות בדף

Add "rep" function per request by User:קיפודנחש at Wikipedia:Lua requests#Template:Loop and Template:Loop15. Copied from sandbox.
הוספת "reverse"
שורה 383: שורה 383:
end
end


--[[  
--[[
    simple function to pipe string.rep to templates.
"Reverse" reverses a string, a'la string.reverse()
]]
]]
str.reverse = function( frame )
    local tab = mw.text.split( frame.args[1] or '', '' )
    local restab = {}
    for i = #tab, 1 do table.insert( restab, tab[i] ) end
    return table.concat( restab )
end


function str.rep( frame )
str['היפוך'] = str.reverse
    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


--[[
--[[