Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:LocationMatch: Difference between revisions

From Gensopedia
Created page with "local p = {} -- Find which ch_x corresponds to the matching location_x function p.findChapter(frame) local args = frame.args local needle = (args.location or ''):gsub('%[%[',''):gsub('%]%]','') for i = 1, 6 do local hay = (args['location_' .. i] or ''):gsub('%[%[',''):gsub('%]%]','') if hay:find(needle, 1, true) then return args['ch_' .. i] or '' end end return 'Unknown' end return p"
 
mNo edit summary
 
Line 1: Line 1:
local p = {}
local p = {}


-- Find which ch_x corresponds to the matching location_x
function p.findChapter(frame)
function p.findChapter(frame)
     local args = frame.args
     local args = frame.args
     local needle = (args.location or ''):gsub('%[%[',''):gsub('%]%]','')
     local needle = (args.location or ''):gsub('%[%[',''):gsub('%]%]','')
    local out = {}  -- collect debug lines
    table.insert(out, 'Needle: ' .. needle)
     for i = 1, 6 do
     for i = 1, 6 do
         local hay = (args['location_' .. i] or ''):gsub('%[%[',''):gsub('%]%]','')
         local hay = (args['location_' .. i] or ''):gsub('%[%[',''):gsub('%]%]','')
        local ch = args['ch_' .. i] or ''
        table.insert(out, string.format("%d → %s (ch %s)", i, hay, ch))
         if hay:find(needle, 1, true) then
         if hay:find(needle, 1, true) then
             return args['ch_' .. i] or ''
             table.insert(out, 'MATCH → ' .. ch)
            return table.concat(out, '<br>')
         end
         end
     end
     end
     return 'Unknown'
 
    table.insert(out, 'No match found')
     return table.concat(out, '<br>')
end
end


return p
return p

Latest revision as of 15:29, 16 December 2025

Documentation for this module may be created at Module:LocationMatch/doc

local p = {}

function p.findChapter(frame)
    local args = frame.args
    local needle = (args.location or ''):gsub('%[%[',''):gsub('%]%]','')
    local out = {}  -- collect debug lines
    table.insert(out, 'Needle: ' .. needle)

    for i = 1, 6 do
        local hay = (args['location_' .. i] or ''):gsub('%[%[',''):gsub('%]%]','')
        local ch = args['ch_' .. i] or ''
        table.insert(out, string.format("%d → %s (ch %s)", i, hay, ch))
        if hay:find(needle, 1, true) then
            table.insert(out, 'MATCH → ' .. ch)
            return table.concat(out, '<br>')
        end
    end

    table.insert(out, 'No match found')
    return table.concat(out, '<br>')
end

return p