Munurin millum rættingarnar hjá "Module:OutputBuffer/doc"

Frá Wikipedia, hin frælsa alfrøðin
Content deleted Content added
Stovnaði síðu við "This module provides an easy and efficient way to generate lengthy strings. == Nýtsla == First, load the module. <source lang="lua"> local newBuffer = require('Module:..."
 
Xqbot (kjak | íkøst)
s Bot: Erstatt forældet <source> -tag og parameteren "enclose" [https://lists.wikimedia.org/pipermail/wikitech-ambassadors/2020-April/002284.html]
 
Linja 5: Linja 5:
First, load the module.
First, load the module.


<source lang="lua">
<syntaxhighlight lang="lua">
local newBuffer = require('Module:OutputBuffer')
local newBuffer = require('Module:OutputBuffer')
</syntaxhighlight>
</source>


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


<source lang="lua">
<syntaxhighlight lang="lua">
local getBuffer, print, printf = newBuffer()
local getBuffer, print, printf = newBuffer()
</syntaxhighlight>
</source>


=== getBuffer ===
=== getBuffer ===


<source lang="lua">
<syntaxhighlight lang="lua">
local text = getBuffer(sep)
local text = getBuffer(sep)
</syntaxhighlight>
</source>


Returns the contents of the buffer, with an optional separator string <var>sep</var>.
Returns the contents of the buffer, with an optional separator string <var>sep</var>.
Linja 25: Linja 25:
=== print ===
=== print ===


<source lang="lua">
<syntaxhighlight lang="lua">
print(s)
print(s)
</syntaxhighlight>
</source>


Adds the string <var>s</var> to the buffer.
Adds the string <var>s</var> to the buffer.
Linja 33: Linja 33:
=== printf ===
=== printf ===


<source lang="lua">
<syntaxhighlight lang="lua">
printf(s, ...)
printf(s, ...)
</syntaxhighlight>
</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]].
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]].
Linja 41: Linja 41:
== Example ==
== Example ==


<source lang="lua">
<syntaxhighlight lang="lua">
local newBuffer = require('Module:OutputBuffer')
local newBuffer = require('Module:OutputBuffer')
local p = {}
local p = {}
Linja 57: Linja 57:
-- {{#invoke:TestModule|main}} would output:
-- {{#invoke:TestModule|main}} would output:
-- "Welcome to the English Wikipedia. There are currently 4500000 articles on this site."
-- "Welcome to the English Wikipedia. There are currently 4500000 articles on this site."
</syntaxhighlight>
</source>


<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox | |
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox | |

Seinasta endurskoðan sum var 22. apr 2020 kl. 16:38

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

Nýtsla[rætta wikitekst]

First, load the module.

local newBuffer = require('Module:OutputBuffer')

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

local getBuffer, print, printf = newBuffer()

getBuffer[rætta wikitekst]

local text = getBuffer(sep)

Returns the contents of the buffer, with an optional separator string sep.

print[rætta wikitekst]

print(s)

Adds the string s to the buffer.

printf[rætta wikitekst]

printf(s, ...)

Adds the string s to the buffer. The string is formatted with any subsequent arguments, following the rules used for string.format.

Example[rætta wikitekst]

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."