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

local p = {}

local ok, data = pcall(mw.loadData, 'Module:SongData/data')

-- {{#invoke:SongData|stat|<key>}} -> the current page's stat
-- {{#invoke:SongData|stat|<key>|page=Other Song}} -> another song's stat
function p.stat(frame)
	local args = frame.args
	local parent = frame:getParent()
	if (not args[1] or args[1] == '') and parent then
		args = parent.args
	end
	local key = args[1]
	local page = args.page
	if not page or page == '' then
		page = mw.title.getCurrentTitle().text
	end
	if not ok or not key then
		return ''
	end
	local rec = data[page]
	if not rec then
		return ''
	end
	local v = rec[mw.text.trim(key)]
	if v == nil then
		return ''
	end
	return tostring(v)
end

return p