Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
IndicWiki Sandbox
Search
Search
English
Log in
Personal tools
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Module:Buffer/doc
(section)
Module
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Stream mode=== ====Buffer:stream==== {{luaself|:stream|args=...}} Switches a Buffer to [[#Stream-Buffer|stream mode]]. While streaming, the __call metamethod will append values to the end of the Buffer instead of the [[#Buffer object|usual op]]. Aside from that, there is only one other function: {{luaself|pre=Stream{{ndash}}|:each}}. Any args passed to Buffer:stream are forwarded to that function for a reason that should be evident when you finish reading this very short section. No special action is needed to exit this 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 (e.g. the <code>..</code> operator). {{anchor|Stream-Buffer}} ====Stream-Buffer object==== {{luaself|pre=Stream-|\|args='string'|args2={concat{{ndash}}list}|args3=(var)}}{{anchor|streaming|calling a Buffer:stream}} Stream-Buffer objects accept only one argument which they append if [[#valid|valid]]. That is, the op is a streamlined version of {{luaself|:_}} sans the ''pos'' and ''raw'' args. This also exploits {{luaref|named arguments|the syntactic sugar of function calls|y}} to append a series of string literals (and tables) with nothing between them (or only {{luaref|Character class|ASCII space chars|y}} if desired). For example, both A and B will produce identical strings: {{#tag:syntaxhighlight|local A = require'Module:Buffer':stream'A string of text may flow'<nowiki />'with nothing between each string' 'or perhaps only a space' 'or even tab and line-break characters'<nowiki />'and continue to append individually'<nowiki />'for use with a joiner' 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 append individually':_'for use with a joiner' mw.log(A==B, A:_str' ') true 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 append individually for use with a joiner |lang=lua}} ====Stream-Buffer:each==== {{luaself|pre=Stream-|:each|args=...}} Appends an undetermined number of [[#valid|valid]] values to the Buffer object.<ref group="note">This is no different than calling the Stream-Buffer object directly with each item in the {{luaref|expression list}}; however, after noting how numbers and variables (too shy to [[skinny dip]] without parenthesis) could look rather odd swimming fully clothed in a stream of naked strings, this was made for those whose aesthetics prefer {{luaself|pre=Stream-|:each|args=('A',arg,'B',arg2)}} over {{code|lang=lua|Stream{{ndash}}Buffer'A'(arg)'B'(arg2)}}.</ref> If the above line gives you [[DΓ©jΓ vu]], that is because it is drawn from {{luaref|mw.html:wikitext|plain=y}}. However, unlike mw.html:wikitext, this does ''not'' stop at the first ''nil'' value.<ref group="note">If you want something like {{code|lang=lua|:wikitext('string1', varName, 'string2')}} such that ''varName'' is shorthand for an {{code|lang=lua|if}} statement that appends ''varName'' and 'string2' when the former is not nil, use {{code|lang=lua|:each('string1', {varName, 'string2'})}} instead.</ref>
Summary:
Please note that all contributions to IndicWiki Sandbox may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
My wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width