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
-
Method Summary
Modifier and TypeMethodDescriptionfinal Buffer
append
(byte b) Append a single byte to the buffer.final Buffer
Append aLuaString
to the buffer.final Buffer
Append aLuaValue
to the buffer.final Buffer
Append a Java String to the buffer.Concatenate this buffer onto aLuaNumber
Concatenate this buffer onto aLuaString
Concatenate this buffer onto aLuaValue
final void
makeroom
(int nbefore, int nafter) Ensure there is enough room before and after the bytes.Concatenate bytes from aLuaString
onto the front of this bufferSet buffer contents as aLuaValue
Convert the buffer to a Java Stringfinal LuaString
tostring()
Convert the buffer to aLuaString
toString()
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:
this
to allow call chaining
-
append
Append aLuaValue
to the buffer.- Returns:
this
to allow call chaining
-
append
Append aLuaString
to the buffer.- Returns:
this
to allow call chaining
-
append
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
Concatenate this buffer onto aLuaValue
- Parameters:
lhs
- the left-hand-side value onto which we are concatenatingthis
- Returns:
Buffer
for use in call chaining.
-
concatTo
Concatenate this buffer onto aLuaString
- Parameters:
lhs
- the left-hand-side value onto which we are concatenatingthis
- Returns:
Buffer
for use in call chaining.
-
concatTo
Concatenate this buffer onto aLuaNumber
The
LuaNumber
will be converted to a string before concatenating.- Parameters:
lhs
- the left-hand-side value onto which we are concatenatingthis
- Returns:
Buffer
for use in call chaining.
-
prepend
Concatenate bytes from aLuaString
onto the front of this buffer- Parameters:
s
- the left-hand-side value which we will concatenate onto the front ofthis
- 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 completesnafter
- number of unused bytes which must follow the data after this completes
-