2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

Module:Sandbox/An196/LuaFrame

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

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

例如:

newTemplateParserValue: <function> (failed)mw.lua:432: frame:newTemplateParserValue: the first parameter must be a table
getParent: <function> (result)...
    newTemplateParserValue: <function> (failed)mw.lua:432: 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:313: 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:313: 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