Module:Test

local data = require("Module:Test/db")

local trim = mw.text.trim -- credit: http://richard.warburton.it -- this version is without trim. local function explode(div,str) if (div=='') then return false end local pos,arr = 0,{} -- for each divider found for st,sp in function return string.find(str,div,pos,true) end do		table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider pos = sp + 1 -- Jump past current divider end table.insert(arr, string.sub(str,pos)) -- Attach chars right of last divider return arr end

-- key: e.g. "BuffName.ManaRegeneration". -- return string or table, nil when key is invalid. local get = function(key) local data, result = data, nil for _, v in ipairs(explode('.', trim(key))) do		if type(data) == 'table' then result = data[v] data = result else break end end return result end

-- args: tables for replacement, e.g.: { ["{0}"] = "Party Girl", [" "] = "Right click" } local getText = function(key, args) local str = get(key) if not str then return end str = string.gsub(str, "%b{}", args) str = string.gsub(str, "%b<>", args) return str end

return { test = get, getText = getText }