Idi na sadržaj

Modul:RepeatString

S Wikipedije, slobodne enciklopedije
Datum izmjene: 12 februar 2014 u 18:44; autor: Edinwiki (razgovor | doprinosi) (Nova strana: -- This module provides a method to repeat a string an arbitrary number of times. Module = {}; Module.RepeatString = function( frame ) local theString = frame.args[1] lo...)
(razl) ← Starija izmjena | Trenutna verzija (razl) | Novija izmjena → (razl)

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 "Error: No string specified."
    elseif stringCount == nil then
        return "Error: No count specified."
    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