Editing
Module:Buffer/doc
(section)
From Thetacola Wiki
Jump to navigation
Jump to search
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!
====Buffer:_var==== {{luaself|:_var|args=var, change|args2={ ... }|args3=()}} Raw appends a Buffer-variable object, which may appear as a different value each time the object (or its container) is converted to a string.<ref group="example">The following contrived example demonstrates most features of {{luaself|:_var|plain=y}}: :{| |{{#tag:syntaxhighlight|local H, sep = require'Module:Buffer':_inHTML('div',{'Heading ',_var={nil,'odd','even'},color='blue',['text-decoration']='underline'}) :_out():_html(true):_html(true):_html(true) sep = H:_in'This is ':_var():_' - ':_var'A':_var(3,-1):_'\n' return H:_in(H(sep)):_(sep) :_'math:':_var():_'+ 5 =':_var(true,5):_';':_var():_out(0,' '):_var(false):_' - 1 = ':_var() --[[ produces: <div style="color:blue;text-decoration:underline">Heading odd</div>This is odd - A3 <div style="color:blue;text-decoration:underline">Heading even</div>This is even - B2 <div style="color:blue;text-decoration:underline">Heading odd</div>This is odd - C1 <div style="color:blue;text-decoration:underline">Heading even</div> This is even - D0 math: 0 + 5 = 5 ; 5 - 1 = 4 --]]|lang=lua}} |}</ref> Initialize a Buffer-variable object by passing as <code>var</code> a: * number - which, when strung the first time, appears as that number and reappears as <code>var + change</code> the next time it is strung. * string - that transforms into the next [[ASCII]] character via {{luaref|string.char||args=var:byte() + change}}. * table - to return the first (non-nil) item, then the second, and so on as determined by {{luaref|next|args=table}}, looping back to the first item after reaching the last. (Note the ''change'' argument does not apply to table-based Buffer-variables.) * custom function - to be set as the _build and __tostring method of a variable-object, though instructions for coding such functions are beyond the scope of this manual. Re-append the same variable object by passing {{code|lang=lua|true}} as the only argument. For non-table-based variables, you may specify ''change'' to append a sister object which transforms the value at the rate specified. Changes are cumulative. Thus, if the original is re-strung after a sister, its value will differ from that of its last appearance by the sum of the original and sister rates and vice versa. Apply a ''change'' without appending a new variable object to the Buffer by passing {{code|lang=lua|false}}. The shift is effective immediately and may affect previously appended variable objects not yet [[#Buffer:_out|finalized]]. Pass only false (i.e., omit ''change'') to produce the same effect as stringing the original once. Note that the false-change is the only ''change'' table-based Buffer variables will honor.<ref group="note">False cycles tables based on {{luaref|Length operator|#|y}} instead of {{luaref|next}}, which may diverge or error if the table contains nil items.</ref> Pass nothing to append a version which simply repeats the result of the last stringing. While generally identical in effect to the object generated by <code>:_var(true, 0)</code>, the Buffer-variable will return nothing if strung before any of its sisters. If passed an explicit nil as the first argument, this is no-op. If passed a boolean before any Buffer-variable has been initialized, this is also a no-op. Note that any op disables future caching at {{luaself|.last_concat|plain=y}} for all Buffer objects in your module (and in any module which may require it). {{anchor|library}}
Summary:
Please note that all contributions to Thetacola Wiki 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
Project:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Page actions
Module
Discussion
Read
Edit source
History
Page actions
Module
Discussion
More
Tools
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Search
Tools
What links here
Related changes
Special pages
Page information