切换搜索
搜索
切换菜单
notifications
切换个人菜单
查看“模块:OutputBuffer/doc”的源代码
来自决策链云智库
更多操作
←
模块:OutputBuffer/doc
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
This module provides an easy and efficient way to generate lengthy strings. == Usage == First, load the module. <syntaxhighlight lang="lua"> local newBuffer = require('Module:OutputBuffer') </syntaxhighlight> Then, create the buffer and the functions that act on it. <syntaxhighlight lang="lua"> local getBuffer, print, printf = newBuffer() </syntaxhighlight> === getBuffer === <syntaxhighlight lang="lua"> local text = getBuffer(sep) </syntaxhighlight> Returns the contents of the buffer, with an optional separator string <var>sep</var>. === print === <syntaxhighlight lang="lua"> print(s) </syntaxhighlight> Adds the string <var>s</var> to the buffer. === printf === <syntaxhighlight lang="lua"> printf(s, ...) </syntaxhighlight> Adds the string <var>s</var> to the buffer. The string is formatted with any subsequent arguments, following the rules used for [[mw:Extension:Scribunto/Lua reference manual#String.format|string.format]]. == Example == <syntaxhighlight lang="lua"> local newBuffer = require('Module:OutputBuffer') local p = {} function p.main() local getBuffer, print, printf = newBuffer() print('Welcome to the English Wikipedia.') printf('There are currently %d articles on this site.', mw.site.stats.articles) return getBuffer(' ') end return p -- Assuming this module's name is "TestModule", and that mw.site.stats.articles returns 4500000, -- {{#invoke:TestModule|main}} would output: -- "Welcome to the English Wikipedia. There are currently 4500000 articles on this site." </syntaxhighlight> <includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox | | <!-- Categories below this line, please; interwikis at Wikidata --> [[Category:Lua metamodules]] }}</includeonly>
返回
模块:OutputBuffer/doc
。