Package com.prineside.luaj
Class Buffer
java.lang.Object
com.prineside.luaj.Buffer
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Bufferappend(byte b) Append a single byte to the buffer.final BufferAppend aLuaStringto the buffer.final BufferAppend aLuaValueto the buffer.final BufferAppend a Java String to the buffer.Concatenate this buffer onto aLuaNumberConcatenate this buffer onto aLuaStringConcatenate this buffer onto aLuaValuefinal voidmakeroom(int nbefore, int nafter) Ensure there is enough room before and after the bytes.Concatenate bytes from aLuaStringonto the front of this bufferSet buffer contents as aLuaValueConvert the buffer to a Java Stringfinal LuaStringtostring()Convert the buffer to aLuaStringtoString()Convert the buffer to a Java Stringvalue()Get buffer contents as aLuaValue
-
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
Create buffer with specified initial value- Parameters:
value- the initial value
-
-
Method Details
-
value
Get buffer contents as aLuaValue- Returns:
- value as a
LuaValue, converting as necessary
-
setvalue
Set buffer contents as aLuaValue- Parameters:
value- value to set
-
tostring
Convert the buffer to aLuaString- Returns:
- the value as a
LuaString
-
tojstring
Convert the buffer to a Java String- Returns:
- the value as a Java String
-
toString
Convert the buffer to a Java String -
append
Append a single byte to the buffer.- Returns:
thisto allow call chaining
-
append
Append aLuaValueto the buffer.- Returns:
thisto allow call chaining
-
append
Append aLuaStringto the buffer.- Returns:
thisto allow call chaining
-
append
Append a Java String to the buffer. The Java string will be converted to bytes using the UTF8 encoding.- Returns:
thisto allow call chaining- See Also:
-
concatTo
Concatenate this buffer onto aLuaValue- Parameters:
lhs- the left-hand-side value onto which we are concatenatingthis- Returns:
Bufferfor use in call chaining.
-
concatTo
Concatenate this buffer onto aLuaString- Parameters:
lhs- the left-hand-side value onto which we are concatenatingthis- Returns:
Bufferfor use in call chaining.
-
concatTo
Concatenate this buffer onto aLuaNumberThe
LuaNumberwill be converted to a string before concatenating.- Parameters:
lhs- the left-hand-side value onto which we are concatenatingthis- Returns:
Bufferfor use in call chaining.
-
prepend
Concatenate bytes from aLuaStringonto the front of this buffer- Parameters:
s- the left-hand-side value which we will concatenate onto the front ofthis- Returns:
Bufferfor 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 completesnafter- number of unused bytes which must follow the data after this completes
-