Module:OutputBuffer/doc

This module provides an easy and efficient way to generate lengthy strings.

Usage
First, load the module.

&#x3c;syntaxhighlight lang="lua"&#x3e; local newBuffer = require('Module:OutputBuffer') &#x3c;/syntaxhighlight&#x3e;

Then, create the buffer and the functions that act on it.

&#x3c;syntaxhighlight lang="lua"&#x3e; local getBuffer, print, printf = newBuffer &#x3c;/syntaxhighlight&#x3e;

getBuffer
&#x3c;syntaxhighlight lang="lua"&#x3e; local text = getBuffer(sep) &#x3c;/syntaxhighlight&#x3e;

Returns the contents of the buffer, with an optional separator string &#x3c;var&#x3e;sep&#x3c;/var&#x3e;.

print
&#x3c;syntaxhighlight lang="lua"&#x3e; print(s) &#x3c;/syntaxhighlight&#x3e;

Adds the string &#x3c;var&#x3e;s&#x3c;/var&#x3e; to the buffer.

printf
&#x3c;syntaxhighlight lang="lua"&#x3e; printf(s, ...) &#x3c;/syntaxhighlight&#x3e;

Adds the string &#x3c;var&#x3e;s&#x3c;/var&#x3e; to the buffer. The string is formatted with any subsequent arguments, following the rules used for string.format.

Example
&#x3c;syntaxhighlight lang="lua"&#x3e; 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, -- would output: -- "Welcome to the English Wikipedia. There are currently 4500000 articles on this site." &#x3c;/syntaxhighlight&#x3e;

&#x3c;includeonly&#x3e;&#x3c;/includeonly&#x3e;