- 你好~!歡迎來到萌娘百科!如果您是第一次來到這裡,點這裡加入萌娘百科!
- 歡迎具有翻譯能力的同學~有意者請點→Category:需要翻譯的條目←
- 如果您在萌娘百科上發現某些內容錯誤/空缺,請勇於修正/添加!編輯萌娘百科其實很容易!
- 歡迎關注 萌娘百科各大平台官方賬號 ~
- 覺得萌娘百科有趣的話,請推薦給朋友哦~
- 萌娘百科新人/遊客群119170500歡迎加入,加入時請寫明【萌百用戶名或擬反饋內容】~
模組:Sandbox/An196/Common
< 模塊: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