跳至內容

bacu-saupu:JSONObject

makayzaay i Wikipitiya

可在bacu-saupu:JSONObject/doc建立此模組的說明文件

local p = {}

function p._get( frame, args )
	
	local default = args["default"]
	local title = args[1]
	
	local page = mw.title.new( title )
	local content = page:getContent()
	if content == nil then
		return default
	end

	local object = mw.text.jsonDecode( content )
	
	local idx = 2
	while args[idx] ~= nil do
		object = object[args[idx]]
		if object == nil and default ~= nil then
			return default
		end
		idx = idx + 1
	end
	
	if type(object) == "table" then
		return default
	end
	
	return object
end

function p.get( frame )
	local args = frame:getParent().args
	
	result = p._get( frame, args )
	if args["preprocess"] then
		result = frame:preprocess( result )
	end
	
	return result
end

return p