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!
==Modified {{code|..}} operator== All "true" Buffer objects{{--}}e.g., the [[#Buffer object|regular]], [[#Stream-Buffer|stream]], and [[#Element-Buffer|element]] varieties{{--}}share the same {{luaref|metatables|__concat metamethod|y}}. Some Buffer-''like'' classes, namely {{luaself|\-HTML object|plain=y}}s and the {{luaself|\-nil object|plain=y}}, also have this same metamethod. The extended {{luaref|Concatenation operator|..}} operator does not append to Buffer objects. In other words, Buffers generally remain the same as before the op excepting those effects that apply whenever Buffers are strung (See {{luaself|.last_concat|plain=y}}, {{luaself|stream mode|plain=y}}, and {{luaself|\-variable|plain=y}}). ===with non-tables=== {{code|lang=lua|Buffer .. value}}<br /> {{code|lang=lua|value .. Buffer}} Any non-table <code>value</code> may be joined a Buffer object with the concatenation operator {{code|lang=lua|..}} without error. With the exception of Element-Buffers (which are a special case), the op passes each object, ordered left-to-right, to {{luaself|:_}} which inserts [[#valid|valid]]ated items in a new table, which this returns through {{luaref|table.concat||y}}. Concatenating an [[#valid|invalid]] ''value'' and a Buffer has generally the same effect as {{luaref|tostring|args=Buffer}} unless such involves: * the Buffer-nil object {{--}} which produces an empty string (instead of nil) * Element-Buffer objects {{--}} which returns the string of the parent Buffer-HTML{{see|#for Element-Buffer objects}} ===with tables=== {{code|lang=lua|Buffer .. table}}<br /> {{code|lang=lua|table .. Buffer}} The same general operation applies for tables as with non-tables{{--}}i.e., [[#valid|validated]] values are inserted left-to-right into a new table to be joined by table.concat. In fact, tables which have a metatable (including Buffer objects which are not an Element-Buffer) are forwarded to Buffer:_ and processed the same way as non-tables. Given a <code>table</code> for which {{luaref|getmetatable||y}} returns nil or false, this instead forwards the table to {{luaself|:_all}}, which iterates every value indexed at a number key in sequential order, inserting those which are valid in the new table. As a reminder, Buffer:_ validates tables with metatables that lack a __tostring method through table.concat, which throws an error on sequences containing one or more value that is neither a string nor a number. Such accounts for nearly all cases of breaking errors involving this op. Note that the ''valKey'' parameter of Buffer:_all is not triggered. ===for Element-Buffers=== {{code|lang=lua|Element-Buffer .. value}}<br /> {{code|lang=lua|value .. Element-Buffer}}<br /> {{code|lang=lua|Element-Buffer .. Element-Buffer}} To recap and expand upon [[#Element-Buffer|§ Element-Buffer-object]], the behavior of this op depends on whether its parent Buffer-HTML is {{luaref|mw.html.create|selfClosing|y}} or if the other ''value'' is also an Element-Buffer. Also, the final result always includes the outer HTML object (i.e., the tag) in some manner. For Element-Buffers of "open" tags, this op creates a table with a metaindex that references the parent of the Element-Buffer. The table is then effectively a "mirror" of the parent Buffer-HTML object except that it contains an empty table at <code>table.nodes</code>{{--}} the index of the Element-Buffer within its parent. This then populates the mirror's inner table with the string of the Element-Buffer and the other value, validated left-to-right, in a manner not unlike what this does with the temporary table it creates when concatenating non-element Buffers to another value. This then returns the mirror table through the __tostring metamethod of the mw.html library, yielding a string which resembles that of the parent tag but with ''value'' inserted in front of or behind the original inner text depending on whether ''value'' was to the left or right of the <code>..</code> operator, respectively. When the selfClosing property of the parent evaluates true, this operates on the parent instead of the Element-Buffer{{--}}i.e., the resulting string will have ''value'' on the outside as opposed to within the tag (placing it inside would be pointless since selfClosing tags do not show inner contents). If both operated objects are Element-Buffers, this mirrors the parent of the first. The inner table of the mirror is then populated by inserting the string of the first Element-Buffer followed by the string the parent Buffer-HMTL of the second. The resulting string would be as though the parent of the second were the last node of the first parent. Note that this Element-to-Element rule does not apply when the first Buffer belongs to a selfClosing tag (in which case, this behaves as though the selfClosing parent were to the left of the operator, returning a string with the selfClosing tag inside the tag of the second Element-Buffer in front the latter's inner contents.) Finally, this combines an Element-Buffer and a table ''value'' which has no metatable by passing the table as ''args'' for {{luaself|pre=Element-|:_add}} with the mirror of the Element-Buffer as the "self". This avoids permanently changing the parent Buffer-HTML by setting a new table at <code>table.attributes</code> or <code>table.styles</code> in the mirror the first time methods such as {{luaref|mw.html:css|plain=y}}, {{luaref|mw.html:attr|plain=y}}, {{luaref|mw.html:addClass|plain=y}}, etc. attempt to access those tables, copying the original's via the recursive form of {{luaself|:_cc}}. Note however that permanent changes may be made to other objects whenever methods such as via {{luaself|args.done}} or {{luaself|args.globalFunction}} are keyed to navigate beyond the mirror or "sandbox". {{anchor|MBpairs}}
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