置顶公告:【置顶】关于临时开启评论区所有功能的公告(2022.10.22) | 【置顶】关于本站Widget恢复使用的公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

Module:Sandbox/An196/LuaFrame

贴贴♀百科,万娘皆可贴的百科全书!转载请标注来源页面的网页链接,并声明引自贴贴百科。内容不可商用。
跳到导航 跳到搜索
Template-info.svg 模块文档  [查看] [编辑] [历史] [刷新]

这个模块用于输出frame框架的所有内容。

例如:

newTemplateParserValue: <function> (failed)mw.lua:430: frame:newTemplateParserValue: the first parameter must be a table
getParent: <function> (result)...
    newTemplateParserValue: <function> (failed)mw.lua:430: frame:newTemplateParserValue: the first parameter must be a table
    getParent: <function> (result)<type 'nil'>
    argumentPairs: <function> (result)<type 'function'>
    extensionTag: <function> (failed)Module:Sandbox/An196/LuaFrame:48: frame:extensionTag: a function name is required
    callParserFunction: <function> (failed)Module:Sandbox/An196/LuaFrame:48: frame:callParserFunction: a function name is required
    preprocess: <function> (result)nil
    getTitle: <function> (result)Module:Sandbox/An196/LuaFrame/doc
    args: <table> ...
        *This table is blank
    newParserValue: <function> (result)...
        expand: <function> (result)nil
    expandTemplate: <function> (failed)mw.lua:311: frame:expandTemplate: the first parameter must be a table
    getArgument: <function> (result)...
        expand: <function> (result)<type 'nil'>
    newChild: <function> (failed)Module:Sandbox/An196/LuaFrame:48: frame:newChild: the first parameter must be a table
argumentPairs: <function> (result)<type 'function'>
extensionTag: <function> (failed)Module:Sandbox/An196/LuaFrame:48: frame:extensionTag: a function name is required
callParserFunction: <function> (failed)Module:Sandbox/An196/LuaFrame:48: frame:callParserFunction: a function name is required
preprocess: <function> (result)nil
getTitle: <function> (result)Module:Sandbox/An196/LuaFrame
args: <table> ...
    2: <string> 2
    3: <string> 3
    1: <string> 1
    4: <string> 4
    arg1: <string> argument1
newParserValue: <function> (result)...
    expand: <function> (result)nil
expandTemplate: <function> (failed)mw.lua:311: frame:expandTemplate: the first parameter must be a table
getArgument: <function> (result)...
    expand: <function> (result)<type 'nil'>
newChild: <function> (failed)Module:Sandbox/An196/LuaFrame:48: frame:newChild: the first parameter must be a table

local p = {}
local content = ""
local rv = nil
local object = nil
local func = nil

-- ==================== Basic Function Start ====================

function p.str(obj)
	local text = ""
	if (type(obj)=="string") then
		text = obj
	elseif (type(obj)=="boolean") then
		if obj then
			text = "true"
		else
			text = "false"
		end
	elseif (type(obj)=="table") then
		text = "{"
		for k, v in pairs(obj) do
			text = text .. p.str(k) .. ":" .. p.str(v)
		end
		text = text .. "}"
	elseif (type(obj)=="number") then
		text = ""..obj
	else
		text = "&lt;type '"..type(obj).."'&gt;"
	end
	return text
end

function p.write(data)
	content = content .. p.str(data)
end

function p.writeln(data)
	content = content .. p.str(data) .. "<br>"
end

function p.color(text, color)
	return [[<span style="color:]] .. p.str(color) .. [[;">]]..p.str(text).."</span>"
end

-- ==================== Basic Function Ended ====================

function p.try()
	rv = func(object)
end

function p.except( err )
	rv = err
end

function p.get(o, f)
	object, func = o, f
	status = xpcall(p.try, p.except)
	return status, rv
end

function p.pair(k, v, indent)
    return indent .. p.color(k, "black") .. ": " .. p.color(" &lt;" .. type(v) .. "&gt; ", "grey")
end

function p.print_table(tab , indent)
	local blank = true
	for k,v in pairs(tab) do
		blank = false
		
		line = p.pair(k, v, indent)
		p.write(line)
		
		result = nil
		if(type(v)=="function") then
			status, result = p.get(tab,v)
			if status then
				p.write(p.color("(result)", "blue"))
			else
				p.write(p.color("(failed)", "red"))
				p.write(p.color(result, "#a00"))
				result = ""
			end
		else
			result = v
		end

		if (type(result)=="table") then
			p.writeln(p.color("...", "purple"))
			p.print_table(result, indent..string.rep("&nbsp;",4))
		else
			p.writeln(p.color(result, "green"))
		end
	end
	if blank then
		p.writeln(indent..p.color("*This table is blank", "grey"))
	end
end

function p.main( frame )
	p.print_table(frame, "")
	return content
end

return p