stdlib 41.2.4 Reference

# Class `std.strbuf`

String buffers.

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

    local StrBuf = require "std.strbuf" {}
    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

## Prototype Chain

    table
     `-> Object
          `-> StrBuf

## Objects

std.strbuf.StrBuf | StrBuf prototype object.

## Functions

std.strbuf.concat (x) | Add a object to a buffer.

## Metamethods

std.strbuf:__concat (buffer, x) | Support concatenation to StrBuf objects.
std.strbuf:__tostring (buffer) | Support fast conversion to Lua string.

## Objects

std.strbuf.StrBuf
  StrBuf prototype object.

  Set also inherits all the fields and methods from std.object.Object.

  ### Fields:

  - _type string object name (default "StrBuf")

  ### See also:

  std.object.__call

  ### Usage:

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

## Functions

Methods

std.strbuf.concat (x)
  Add a object to a buffer. Elements are stringified lazily, so if 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:

  std.strbuf.StrBuf modified buffer

  ### Usage:

      buf = buf:concat "append this" {" and", " this"}

## Metamethods

std.strbuf:__concat (buffer, x)
  Support concatenation to StrBuf objects.

  ### Parameters:

  - buffer std.strbuf.StrBuf object
  - x a string, or object that can be coerced to a string

  ### Returns:

  std.strbuf.StrBuf modified buf

  ### See also:

  std.strbuf.concat

  ### Usage:

      buf = buf .. x

std.strbuf:__tostring (buffer)
  Support fast conversion to Lua string.

  ### Parameters:

  - buffer std.strbuf.StrBuf object

  ### Returns:

  string concatenation of buffer contents

  ### See also:

  tostring

  ### Usage:

      str = tostring (buf)

generated by LDoc 1.5.0 Last updated 2026-07-26 11:03:27