Content deleted Content added
save... note: Buffer:stream is not yet live |
save |
||
Line 1:
{{Tmbox|image=[[File:Stop_hand_nuvola.svg|40px]]|text=Do not "beautify" the source of this metamodule. Its unconventional syntax was developed using the [[scientific method]] for performance. For example, {{code|lang=lua|1=v2~=true and v2~=false}}, though longer than {{code|lang=lua|1=type(v2)=='boolean'}}, runs about 8 times faster. (While {{luaref|type}} is generally inexpensive, any "[[Aerodynamic drag|drag]]" on this metamodule is multiplied by the millions of pages that transclude it.)}}
{{Module rating |release<!-- Values: pre-alpha • alpha • beta • release • protected -- If a rating not needed/relevant, delete this template call -->}}
<!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see [[Wikipedia:Wikidata]]) -->
Line 38 ⟶ 40:
{{luaself|:_|args='string'|args2=value, pos, raw|args3=value, raw}}
:''See also {{luaself|:stream|Stream mode}} for a faster, simpler version of this op.
Appends a value to the Buffer. In rough terms, {{code|lang=lua|Buffer:_'string1':_'string2'}} is the same as {{code|lang=lua|Buffer {{=}} Buffer..'string1'..'string2'}}. (It may help to imagine {{code|:_}} as a {{code|..}} that has stood up and is now casting a shadow.)
Line 148 ⟶ 151:
===Buffer:stream===
{{luaself|:stream|args='string'|args2={
Switches the Buffer to stream mode. In this mode, the [[#call Buffer object|Buffer call]] operation, instead of returning a string, now acts as
When streaming, you may append a sequence of strings with nothing
{{#tag:syntaxhighlight| local A = require'Module:Buffer':stream'A string of text may flow''with nothing between each string' 'or perhaps only a space'
'or even tab and line-break characters'
local B = require'Module:Buffer':_'A string of text may flow':_'with nothing between each string' :_ 'or perhaps only a space'
:_'or even tab and line-break characters':_'and continue to
=mw.dumpObject{A
table#1 {
"A string of text may flow with nothing between each string or perhaps only a space or even tab and line-break characters and continue to
true,
}|lang=lua}}▼
▲|lang=lua}}
Aside from saving two characters per string, this mode runs about [[#performance|50 percent faster]] (which says a lot considering :_ is much faster than the .. op). Despite the lack of any operator between each call, this is still a {{luaref|Function calls|function call|y}}; in other words, you must still wrap numbers and variables in parentheses {{code|()}}.<ref group=note>Instead of passing a number type, pass a number string (i.e. {{code|lang=lua|Buffer:stream'1'}} instead of {{code|lang=lua|Buffer:stream(1)}}). Such improves performance (and is more aesthetically pleasing in this mode).</ref>
====Returning to normal mode====
No explicit action is needed to exit stream mode. The normal call to string op is restored upon the use of any regular Buffer function or any operation which coerces the Buffer into a string.
|