模块:Out:修订间差异
来自Limbo Wiki Mirror
| 小无编辑摘要 | 小 已从limbowiki:模块:Out导入4个版本 | ||
| (未显示另一用户的1个中间版本) | |||
| 第1行: | 第1行: | ||
| local out = {}  -- out模块 | local out = {}  -- out模块 | ||
| out.content = "" | |||
| function out.str(obj)  -- 获取对象的字符串表示(似乎可以使用mw.logObject替代) | function out.str(obj)  -- 获取对象的字符串表示(似乎可以使用mw.logObject替代) | ||
| 第27行: | 第27行: | ||
| function out.write(data)  -- 不换行输出 | function out.write(data)  -- 不换行输出 | ||
| 	content = content .. out.str(data) | 	out.content = out.content .. out.str(data) | ||
| end | end | ||
| function out.writeln(data)  -- 换行输出 | function out.writeln(data)  -- 换行输出 | ||
| 	content = content .. out.str(data) .. "<br>" | 	out.content = out.content .. out.str(data) .. "<br>" | ||
| end | end | ||
| 第41行: | 第41行: | ||
| 	function warp(frame) | 	function warp(frame) | ||
| 		base(frame) | 		base(frame) | ||
| 		return frame:preprocess(content)  -- 预处理,使html和模板生效 | 		return frame:preprocess(out.content)  -- 预处理,使html和模板生效 | ||
| 	end | 	end | ||
| 	return warp | 	return warp | ||
2025年6月26日 (四) 13:42的最新版本
版权提示:该模块有位于其它平台的不同版本,可能有微小差异,不保证同步更新。同时,允许您搬运此模块。
简单输出库
这是一个简单的输出轮子。
不应当在页面内显式使用#invoke调用,请在您的模块中使用下面的语句导入这个库。
local out=require("Module:Out")
使用
目前有以下函数:
- 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 = {}  -- out模块
out.content = ""
 
function out.str(obj)  -- 获取对象的字符串表示(似乎可以使用mw.logObject替代)
	local rv = ""
	if (type(obj)=="string") then
		rv = obj
	elseif (type(obj)=="boolean") then
		if obj then
		    rv = "true"
		else
			rv = "false"
		end
	elseif (type(obj)=="number") then
		rv = "" .. obj
	elseif (type(obj)=="table") then
		rv = "{"
		for k, v in pairs(obj) do
			rv = rv .. out.str(k) .. ":" .. out.str(v)
		end
		rv = rv .. "}"
	else
		rv = "<type '"..type(obj).."'>"
	end
	return rv
end
 
function out.write(data)  -- 不换行输出
	out.content = out.content .. out.str(data)
end
 
function out.writeln(data)  -- 换行输出
	out.content = out.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(out.content)  -- 预处理,使html和模板生效
	end
	return warp
end
-- 导入请使用
-- local out=require("Module:Out")
return out
