FANDOM


This module provides an easy and efficient way to generate lengthy strings.
 
== Usage ==
 
First, load the module.
 
<source lang="lua">
local newBuffer = require('Module:OutputBuffer')
</source>
 
Then, create the buffer and the functions that act on it.
 
<source lang="lua">
local getBuffer, print, printf = newBuffer()
</source>
 
=== getBuffer ===
 
<source lang="lua">
local text = getBuffer(sep)
</source>
 
Returns the contents of the buffer, with an optional separator string <var>sep</var>.
 
=== print ===
 
<source lang="lua">
print(s)
</source>
 
Adds the string <var>s</var> to the buffer.
 
=== printf ===
 
<source lang="lua">
printf(s, ...)
</source>
 
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 ==
 
<source 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."
</source>
 
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox | |
<!-- Categories below this line, please; interwikis at Wikidata -->
[[Category:Lua metamodules]]
}}</includeonly>

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.