Module:Sandbox/An196/LuaFrame
这个模块用于输出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 = "<type '"..type(obj).."'>"
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(" <" .. type(v) .. "> ", "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(" ",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