Модуль:Песочница/PtQa

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
Документация
--
local p = {}
function p.count(frame)
    local source = frame.args[1]
    local letter = frame.args[2]
    local my_string = mw.title.new(source):getContent()
    local i = {}
    local all_count = 0
    local section=0
    local setme = 0
    for i = 1, string.len(my_string), 1 do
        cur_c = string.sub(my_string, i, i)
        next_c = string.sub(my_string, i+1, i+1)
        next2_c = string.sub(my_string, i+2, i+2)
        if cur_c == '=' and next_c == '=' and  next2_c == letter then
            section = 2
        end
        if cur_c == '=' and next_c == '=' and next2_c ~= letter then
            section = section - 1
        end
        if section == 1 and cur_c == '#' and next_c ~= '*' and next_c ~= ':' then
           all_count = all_count + 1
           setme = all_count
        end
    i = i + 1
    end
    return all_count
end
return p