本站页面(多半)转载自萌娘百科的同名页面,依CC BY-NC-SA 3.0引入,贡献者可以在历史页查询。
因各种原因页面内容可能和源页面有所出入,非本站特有页面内容请以萌娘百科为准。
因各种原因页面内容可能和源页面有所出入,非本站特有页面内容请以萌娘百科为准。
- 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
- 本镜像站和其他萌娘百科的镜像站无关,请注意分别。
Module:Sandbox/An196/Common
< Module:Sandbox | An196
跳到导航
跳到搜索
版权提示:该模块有位于其它平台的不同版本,可能有微小差异,不保证同步更新。同时,允许您搬运此模块。
简单输出库
这是一个简单的输出轮子。
不应当在页面内显式使用#invoke调用,请在您的模块中使用下面的语句导入这个库。
local out=require("Module:Sandbox/An196/Common")
使用
目前有以下函数:
out.str(obj)
-- 获取对象的字符串表示(似乎可以使用mw.logObject替代)out.write(data)
-- 不换行输出out.writeln(data)
-- 换行输出out.color(text, color)
-- 颜色输出:用带颜色的span包围text。out.create_main(base)
-- main函数装饰器,自动返回结果
使用main装饰器,您应该
p.main = out.create_main(p.run)
local out = {} local content = "" function out.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 .. out.str(k) .. ":" .. out.str(v) end text = text .. "}" elseif (type(obj)=="number") then text = ""..obj else text = "<type '"..type(obj).."'>" end return text end function out.write(data) content = content .. out.str(data) end function out.writeln(data) content = content .. out.str(data) .. "<br>" end function out.color(text, color) return [[<span style="color:]] .. out.str(color) .. [[;">]]..out.str(text).."</span>" end function out.create_main(base) function warp(frame) base(frame) return frame:preprocess(content) end return warp end return out