Class Buffer

java.lang.Object
com.prineside.luaj.Buffer

public final class Buffer extends Object
String buffer for use in string library methods, optimized for production of StrValue instances.

The buffer can begin initially as a wrapped LuaValue and only when concatenation actually occurs are the bytes first copied.

To convert back to a LuaValue again, the function value() is used.

See Also:
  • Constructor Details

    • Buffer

      public Buffer()
      Create buffer with default capacity
      See Also:
      • DEFAULT_CAPACITY
    • Buffer

      public Buffer(int initialCapacity)
      Create buffer with specified initial capacity
      Parameters:
      initialCapacity - the initial capacity
    • Buffer

      public Buffer(LuaValue value)
      Create buffer with specified initial value
      Parameters:
      value - the initial value
  • Method Details

    • value

      public LuaValue value()
      Get buffer contents as a LuaValue
      Returns:
      value as a LuaValue, converting as necessary
    • setvalue

      public Buffer setvalue(LuaValue value)
      Set buffer contents as a LuaValue
      Parameters:
      value - value to set
    • tostring

      public final LuaString tostring()
      Convert the buffer to a LuaString
      Returns:
      the value as a LuaString
    • tojstring

      public String tojstring()
      Convert the buffer to a Java String
      Returns:
      the value as a Java String
    • toString

      public String toString()
      Convert the buffer to a Java String
      Overrides:
      toString in class Object
      Returns:
      the value as a Java String
    • append

      public final Buffer append(byte b)
      Append a single byte to the buffer.
      Returns:
      this to allow call chaining
    • append

      public final Buffer append(LuaValue val)
      Append a LuaValue to the buffer.
      Returns:
      this to allow call chaining
    • append

      public final Buffer append(LuaString str)
      Append a LuaString to the buffer.
      Returns:
      this to allow call chaining
    • append

      public final Buffer append(String str)
      Append a Java String to the buffer. The Java string will be converted to bytes using the UTF8 encoding.
      Returns:
      this to allow call chaining
      See Also:
    • concatTo

      public Buffer concatTo(LuaValue lhs)
      Concatenate this buffer onto a LuaValue
      Parameters:
      lhs - the left-hand-side value onto which we are concatenating this
      Returns:
      Buffer for use in call chaining.
    • concatTo

      public Buffer concatTo(LuaString lhs)
      Concatenate this buffer onto a LuaString
      Parameters:
      lhs - the left-hand-side value onto which we are concatenating this
      Returns:
      Buffer for use in call chaining.
    • concatTo

      public Buffer concatTo(LuaNumber lhs)
      Concatenate this buffer onto a LuaNumber

      The LuaNumber will be converted to a string before concatenating.

      Parameters:
      lhs - the left-hand-side value onto which we are concatenating this
      Returns:
      Buffer for use in call chaining.
    • prepend

      public Buffer prepend(LuaString s)
      Concatenate bytes from a LuaString onto the front of this buffer
      Parameters:
      s - the left-hand-side value which we will concatenate onto the front of this
      Returns:
      Buffer for use in call chaining.
    • makeroom

      public final void makeroom(int nbefore, int nafter)
      Ensure there is enough room before and after the bytes.
      Parameters:
      nbefore - number of unused bytes which must precede the data after this completes
      nafter - number of unused bytes which must follow the data after this completes