Module std.prototype.strbuf

StrBuf Prototype.

Buffers are mutable by default, but being based on objects, they can also be used in a functional style:

local StrBuf = require 'std.prototype.strbuf'.prototype
local a = StrBuf {'a'}
local b = a:concat 'b'      -- mutate *a*
print(a, b)                 --> ab   ab
local c = a {} .. 'c'       -- copy and append
print(a, c)                 --> ab   abc

In addition to the functionality described here, StrBuf objects also have all the methods and metamethods of the prototype.object.prototype (except where overridden here),

Prototype Chain

table
 `-> Container
      `-> Object
           `-> StrBuf

Objects

prototype StrBuf prototype object.

Metamethods

prototype:__concat (x) Support concatenation to StrBuf objects.
prototype:__tostring () Support fast conversion to Lua string.

Methods

prototype:concat (x) Add a object to a buffer.


Objects

prototype
StrBuf prototype object.

Fields:

  • _type string object name (default 'StrBuf')

See also:

Usage:

    local StrBuf = require 'std.prototype.strbuf'.prototype
    local a = StrBuf {1, 2, 3}
    local b = StrBuf {a, 'five', 'six'}
    a = a .. 4
    b = b:concat 'seven'
    print(a, b) --> 1234    1234fivesixseven
    os.exit(0)

Metamethods

prototype:__concat (x)
Support concatenation to StrBuf objects.

Parameters:

  • x a string, or object that can be coerced to a string

Returns:

    prototype modified buf

See also:

Usage:

    buf = buf .. x
prototype:__tostring ()
Support fast conversion to Lua string.

Returns:

    string concatenation of buffer contents

See also:

Usage:

    str = tostring(buf)

Methods

prototype:concat (x)
Add a object to a buffer. Elements are stringified lazily, so if you add a table and then change its contents, the contents of the buffer will be affected too.

Parameters:

  • x object to add to buffer

Returns:

    prototype modified buffer

Usage:

    c = StrBuf {} :concat 'append this' :concat(StrBuf {' and', ' this'})
generated by LDoc 1.5.0 Last updated 2026-10-28 10:28:35