Jump to content

Module:DatasetLoader

Revision as of 01:31, 18 May 2025 by MarkWD (talk | contribs) (// via Wikitext Extension for VSCode)

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

-- Module:DatasetLoader
-- Central loader for Data: JSON assets via JsonConfig or mw.loadData, cached per render

local loader = {}

-- Returns a Lua table for the named dataset, or {} on failure
function loader.get(name)
    -- Try JsonConfig extension first
    if mw.ext and mw.ext.data and mw.ext.data.get then
        local ok, data = pcall(mw.ext.data.get, name)
        if ok and data then
            return data
        end
    end

    -- Fallback to mw.loadData for Data: namespace
    local ok2, data2 = pcall(mw.loadData, 'Data:' .. name .. '.json')
    if ok2 and data2 then
        return data2
    end

    -- Ultimate fallback: empty table
    return {}
end

return loader