Modul:RepeatString

Dokumentaciju za ovaj modul možete napraviti na stranici Modul:RepeatString/dok

-- This module provides a method to repeat a string an arbitrary number of times.

Module = {};

Module.RepeatString = function( frame )

    local theString   = frame.args[1]
    local stringCount = tonumber(frame.args[2])

    if theString == nil then
        return "Greška: Niz nije naveden."
    elseif stringCount == nil then
        return "Greška: Broj nije naveden."
    end

    -- Initialize a table. More memory-efficient than string concatenation;
    -- see "Concatenation operator" in the Scribunto Lua reference manual.
    local result  = {}
    local repeats = 0

    while ( repeats <= stringCount ) do
        result[repeats] = theString
        repeats = repeats + 1
    end

    return table.concat( result )

end

return Module