Class LuaString
- All Implemented Interfaces:
com.esotericsoftware.kryo.KryoSerializable
LuaValue
for representing lua strings.
Because lua string values are more nearly sequences of bytes than
sequences of characters or unicode code points, the LuaString
implementation holds the string value in an internal byte array.
LuaString
values are not considered mutable once constructed,
so multiple LuaString
values can chare a single byte array.
Currently LuaString
s are pooled via a centrally managed weak table.
To ensure that as many string values as possible take advantage of this,
Constructors are not exposed directly. As with number, booleans, and nil,
instance construction should be via LuaValue.valueOf(byte[])
or similar API.
Because of this pooling, users of LuaString must not directly alter the bytes in a LuaString, or undefined behavior will result.
When Java Strings are used to initialize LuaString
data, the UTF8 encoding is assumed.
The functions
lengthAsUtf8(char[])
,
encodeToUtf8(char[], int, byte[], int)
, and
decodeAsUtf8(byte[], int, int)
are used to convert back and forth between UTF8 byte arrays and character arrays.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.prineside.luaj.LuaValue
LuaValue.NillableSerializer, LuaValue.None
-
Field Summary
FieldsModifier and TypeFieldDescriptionbyte[]
The bytes for the string.int
The number of bytes that comprise this stringint
The offset into the byte array, 0 means start at the first bytestatic LuaValue
The singleton instance for string metatables that forwards to the string functions.Fields inherited from class com.prineside.luaj.LuaValue
ADD, CALL, CONCAT, DIV, EMPTYSTRING, ENV, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILLABLE_SERIALIZER, NILS, NONE, NOVALS, ONE, POW, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, ZERO
-
Method Summary
Modifier and TypeMethodDescriptionadd
(double rhs) Add: Perform numeric add operation with another value of double type with metatag processingadd
(int rhs) Add: Perform numeric add operation with another value of int type with metatag processingAdd: Perform numeric add operation with another value including metatag processing.int
charAt
(int index) double
Check that the value is numeric and return the value as a double, or throwLuaError
if not numericint
checkint()
Check that the value is numeric, and convert and cast value to int, or throwLuaError
if not numericCheck that the value is numeric, and convert and cast value to int, or throwLuaError
if not numericConvert this value to a Java String.long
Check that the value is numeric, and convert and cast value to long, or throwLuaError
if not numericCheck that the value is numeric, and return as a LuaNumber if so, or throwLuaError
checknumber
(String msg) Check that the value is numeric, and return as a LuaNumber if so, or throwLuaError
Check that this is a lua string, or throwLuaError
if it is not.Concatenate aBuffer
onto this value and return the result using rules of lua string concatenation including metatag processing.Concatenate another value onto this value and return the result using rules of lua string concatenation including metatag processing.Reverse-concatenation: concatenate this value onto another value known to be aLuaNumber
and return the result using rules of lua string concatenation including metatag processing.Reverse-concatenation: concatenate this value onto another value known to be aLuaString
and return the result using rules of lua string concatenation including metatag processing.void
copyInto
(int strOffset, byte[] bytes, int arrayOffset, int len) Copy the bytes of the string into the given byte array.static String
decodeAsUtf8
(byte[] bytes, int offset, int length) Convert to Java String interpreting as utf8 characters.div
(double rhs) Divide: Perform numeric divide operation by another value of double type without metatag processingdiv
(int rhs) Divide: Perform numeric divide operation by another value of int type without metatag processingDivide: Perform numeric divide operation by another value of unknown type, including metatag processing.divInto
(double lhs) Reverse-divide: Perform numeric divide operation into another value with metatag processingstatic int
encodeToUtf8
(char[] chars, int nchars, byte[] bytes, int off) Encode the given Java string as UTF-8 bytes, writing the result to bytes starting at offset.Equals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ
.boolean
Equals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ
, and return java booleanstatic boolean
equals
(byte[] a, int i, byte[] b, int j, int n) static boolean
boolean
Get the metatable for thisLuaValue
Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returningLuaValue
.boolean
gt_b
(double rhs) Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.boolean
gt_b
(int rhs) Greater than: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.boolean
Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.Greater than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returningLuaValue
.boolean
gteq_b
(double rhs) Greater than or equals: Perform numeric comparison with another value of double type, including metatag processing, and returning java boolean.boolean
gteq_b
(int rhs) Greater than or equals: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.boolean
Greater than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.int
hashCode()
static int
hashCode
(byte[] bytes, int offset, int length) Compute the hash code of a sequence of bytes within a byte array using lua's rules for string hashes.int
indexOf
(byte b, int start) Find the index of a byte starting at a point in this stringint
Find the index of a string starting at a point in this stringint
indexOfAny
(LuaString accept) Java version of strpbrk - find index of any byte that in an accept string.boolean
isint()
Check ifthis
is anumber
and is representable by java int without rounding or truncationboolean
islong()
Check ifthis
is anumber
and is representable by java long without rounding or truncationboolean
isnumber()
Check ifthis
is anumber
boolean
isstring()
Check ifthis
is astring
boolean
Check that a byte sequence is valid UTF-8int
Find the last index of a string in this stringlen()
Length operator: return lua length of object(#this)
including metatag processing as java intint
length()
Length operator: return lua length of object(#this)
including metatag processing as java intstatic int
lengthAsUtf8
(char[] chars) Count the number of bytes required to encode the string as UTF-8.Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returningLuaValue
.boolean
lt_b
(double rhs) Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.boolean
lt_b
(int rhs) Less than: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.boolean
Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.Less than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returningLuaValue
.boolean
lteq_b
(double rhs) Less than or equals: Perform numeric comparison with another value of double type, including metatag processing, and returning java boolean.boolean
lteq_b
(int rhs) Less than or equals: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.boolean
Less than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.int
luaByte
(int index) mod
(double rhs) Modulo: Perform numeric modulo operation with another value of double type without metatag processingmod
(int rhs) Modulo: Perform numeric modulo operation with another value of int type without metatag processingModulo: Perform numeric modulo operation with another value of unknown type, including metatag processing.modFrom
(double lhs) Reverse-modulo: Perform numeric modulo operation from another value with metatag processingmul
(double rhs) Multiply: Perform numeric multiply operation with another value of double type with metatag processingmul
(int rhs) Multiply: Perform numeric multiply operation with another value of int type with metatag processingMultiply: Perform numeric multiply operation with another value of unknown type, including metatag processing.neg()
Unary minus: return negative value(-this)
as defined by lua unary minus operatordouble
optdouble
(double defval) Check that optional argument is a number or string convertible to number and return as doubleint
optint
(int defval) Check that optional argument is a number or string convertible to number and return as intoptinteger
(LuaInteger defval) Check that optional argument is a number or string convertible to number and return asLuaInteger
optjstring
(String defval) Check that optional argument is a string or number and return as Java Stringlong
optlong
(long defval) Check that optional argument is a number or string convertible to number and return as longCheck that optional argument is a number or string convertible to number and return asLuaNumber
Check that optional argument is a string or number and return asLuaString
pow
(double rhs) Raise to power: Raise this value to a power of double type with metatag processingpow
(int rhs) Raise to power: Raise this value to a power of int type with metatag processingRaise to power: Raise this value to a power including metatag processing.powWith
(double lhs) Reverse-raise to power: Raise another value of double type to this power with metatag processingpowWith
(int lhs) Reverse-raise to power: Raise another value of double type to this power with metatag processingvoid
Print the bytes of the LuaString to a PrintStream as if it were an ASCII string, quoting and escaping control characters.boolean
Equals: Perform direct equality comparison with aLuaString
value without metatag processing.boolean
Equals: Perform direct equality comparison with another value without metatag processing.int
rawlen()
Get raw length of table or string without metatag processing.void
read
(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input) double
Convert to a number in base 10, or base 16 if the string starts with '0x', or return Double.NaN if it cannot be converted to a number.double
scannumber
(int base) Convert to a number in a base, or return Double.NaN if not a number.int
Perform string comparison with another value known to be aLuaString
using string comparison based on byte values.int
Perform string comparison with another value of any type using string comparison based on byte values.strvalue()
sub
(double rhs) Subtract: Perform numeric subtract operation with another value of double type with metatag processingsub
(int rhs) Subtract: Perform numeric subtract operation with another value of int type with metatag processingSubtract: Perform numeric subtract operation with another value of unknown type, including metatag processing.subFrom
(double lhs) Reverse-subtract: Perform numeric subtract operation from an int value with metatag processingsubstring
(int beginIndex, int endIndex) Take a substring using Java zero-based indexes for begin and end or range.byte
tobyte()
Convert to byte if numeric, or 0 if not.char
tochar()
Convert to char if numeric, or 0 if not.double
todouble()
Convert to double if numeric, or 0 if not.float
tofloat()
Convert to float if numeric, or 0 if not.Convert value to an input stream.int
toint()
Convert to int if numeric, or 0 if not.Convert to human readable String for any type.long
tolong()
Convert to long if numeric, or 0 if not.tonumber()
convert to a number using baee 10 or base 16 if it starts with '0x', or NIL if it can't be convertedtonumber
(int base) convert to a number using a supplied base, or NIL if it can't be convertedshort
toshort()
Convert to short if numeric, or 0 if not.tostring()
Conditionally convert to lua string without throwing errors.int
type()
Get the enumeration value for the type of this value.typename()
Get the String name of the type of this value.static LuaString
valueOf
(byte[] bytes) Construct aLuaString
for all the bytes in a byte array.static LuaString
valueOf
(byte[] bytes, int off, int len) Construct aLuaString
for a portion of a byte array.static LuaString
valueOf
(char[] bytes) Construct aLuaString
using the supplied characters as byte values.static LuaString
valueOf
(char[] bytes, int off, int len) Construct aLuaString
using the supplied characters as byte values.static LuaString
Get aLuaString
instance whose bytes match the supplied Java String using the UTF8 encoding.static LuaString
valueUsing
(byte[] bytes) Construct aLuaString
for all the bytes in a byte array, possibly using the supplied array as the backing store.static LuaString
valueUsing
(byte[] bytes, int off, int len) Construct aLuaString
around, possibly using the the supplied byte array as the backing store.void
write
(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output output) void
write
(DataOutputStream writer, int i, int len) Methods inherited from class com.prineside.luaj.LuaValue
and, arg, arg1, argerror, assert_, buffer, cachedDouble, cachedInt, cachedVarargsOf, cachedVarargsOf, cachedVarargsOf, cachedVarargsOf, cachedVarargsOf, cachedVarargsOf, call, call, call, call, call, checkboolean, checkclosure, checkfunction, checkglobals, checknotnil, checktable, checkthread, checkuserdata, checkuserdata, comparemt, concatmt, concatTo, eqmtcall, error, get, get, get, gt, gt, gteq, gteq, inext, initupvalue1, invoke, invoke, invoke, invoke, invoke, invoke, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, isboolean, isclosure, isfunction, isinttype, isnil, istable, isthread, isuserdata, isuserdata, isvalidkey, listOf, listOf, load, lt, lt, lteq, lteq, metatag, method, method, method, method, method, method, narg, neq, neq_b, next, not, onInvoke, optboolean, optclosure, optfunction, opttable, optthread, optuserdata, optuserdata, optvalue, or, presize, raweq, raweq, raweq, rawget, rawget, rawget, rawset, rawset, rawset, rawset, rawset, rawset, rawset, rawsetlist, set, set, set, set, set, set, set, setmetatable, strongvalue, subargs, subFrom, tableOf, tableOf, tableOf, tableOf, tableOf, tableOf, tailcallOf, testfor_b, toboolean, toString, touserdata, touserdata, userdataOf, userdataOf, valueOf, valueOf, valueOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOf
Methods inherited from class com.prineside.luaj.Varargs
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, dealias, eval, isfunction, isnil, isnoneornil, isnumber, isstring, istable, isTailcall, isthread, isuserdata, isvalue, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optnumber, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, touserdata, touserdata, type
-
Field Details
-
s_metatable
The singleton instance for string metatables that forwards to the string functions. Typically, this is set to the string metatable as a side effect of loading the string library, and is read-write to provide flexible behavior by default. When used in a server environment where there may be roge scripts, this should be replaced with a read-only table since it is shared across all lua code in this Java VM. -
m_bytes
public byte[] m_bytesThe bytes for the string. These must not be mutated directly because the backing may be shared by multiple LuaStrings, and the hash code is computed only at construction time. It is exposed only for performance and legacy reasons. -
m_offset
public int m_offsetThe offset into the byte array, 0 means start at the first byte -
m_length
public int m_lengthThe number of bytes that comprise this string
-
-
Method Details
-
write
public void write(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output output) - Specified by:
write
in interfacecom.esotericsoftware.kryo.KryoSerializable
-
read
public void read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input) - Specified by:
read
in interfacecom.esotericsoftware.kryo.KryoSerializable
-
valueOf
Get aLuaString
instance whose bytes match the supplied Java String using the UTF8 encoding.- Parameters:
string
- Java String containing characters to encode as UTF8- Returns:
LuaString
with UTF8 bytes corresponding to the supplied String
-
valueOf
Construct aLuaString
for a portion of a byte array.The array is first be used as the backing for this object, so clients must not change contents. If the supplied value for 'len' is more than half the length of the container, the supplied byte array will be used as the backing, otherwise the bytes will be copied to a new byte array, and cache lookup may be performed.
- Parameters:
bytes
- byte bufferoff
- offset into the byte bufferlen
- length of the byte buffer- Returns:
LuaString
wrapping the byte buffer
-
valueUsing
Construct aLuaString
around, possibly using the the supplied byte array as the backing store.The caller must ensure that the array is not mutated after the call. However, if the string is short enough the short-string cache is checked for a match which may be used instead of the supplied byte array.
- Parameters:
bytes
- byte buffer- Returns:
LuaString
wrapping the byte buffer, or an equivalent string.
-
valueOf
Construct aLuaString
using the supplied characters as byte values.Only the low-order 8-bits of each character are used, the remainder is ignored.
This is most useful for constructing byte sequences that do not conform to UTF8.
- Parameters:
bytes
- array of char, whose values are truncated at 8-bits each and put into a byte array.- Returns:
LuaString
wrapping a copy of the byte buffer
-
valueOf
Construct aLuaString
using the supplied characters as byte values.Only the low-order 8-bits of each character are used, the remainder is ignored.
This is most useful for constructing byte sequences that do not conform to UTF8.
- Parameters:
bytes
- array of char, whose values are truncated at 8-bits each and put into a byte array.- Returns:
LuaString
wrapping a copy of the byte buffer
-
valueOf
Construct aLuaString
for all the bytes in a byte array.The LuaString returned will either be a new LuaString containing a copy of the bytes array, or be an existing LuaString used already having the same value.
- Parameters:
bytes
- byte buffer- Returns:
LuaString
wrapping the byte buffer
-
valueUsing
Construct aLuaString
for all the bytes in a byte array, possibly using the supplied array as the backing store.The LuaString returned will either be a new LuaString containing the byte array, or be an existing LuaString used already having the same value.
The caller must not mutate the contents of the byte array after this call, as it may be used elsewhere due to recent short string caching.
- Parameters:
bytes
- byte buffer- Returns:
LuaString
wrapping the byte buffer
-
isstring
public boolean isstring()Description copied from class:LuaValue
Check ifthis
is astring
-
getmetatable
Description copied from class:LuaValue
Get the metatable for thisLuaValue
For
LuaTable
andLuaUserdata
instances, the metatable returned is this instance metatable. For all other types, the class metatable value will be returned.- Overrides:
getmetatable
in classLuaValue
- Returns:
- metatable, or null if it there is none
- See Also:
-
type
public int type()Description copied from class:LuaValue
Get the enumeration value for the type of this value.- Specified by:
type
in classLuaValue
- Returns:
- value for this type, one of
LuaValue.TNIL
,LuaValue.TBOOLEAN
,LuaValue.TNUMBER
,LuaValue.TSTRING
,LuaValue.TTABLE
,LuaValue.TFUNCTION
,LuaValue.TUSERDATA
,LuaValue.TTHREAD
- See Also:
-
typename
Description copied from class:LuaValue
Get the String name of the type of this value.- Specified by:
typename
in classLuaValue
- Returns:
- name from type name list
LuaValue.TYPE_NAMES
corresponding to the type of this value: "nil", "boolean", "number", "string", "table", "function", "userdata", "thread" - See Also:
-
tojstring
Description copied from class:LuaValue
Convert to human readable String for any type. -
neg
Description copied from class:LuaValue
Unary minus: return negative value(-this)
as defined by lua unary minus operator- Overrides:
neg
in classLuaValue
- Returns:
- boolean inverse as
LuaBoolean
if boolean or nil, numeric inverse asLuaNumber
if numeric, or metatag processing result ifLuaValue.UNM
metatag is defined
-
add
Description copied from class:LuaValue
-
add
Description copied from class:LuaValue
Add: Perform numeric add operation with another value of double type with metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a number -
add
Description copied from class:LuaValue
Add: Perform numeric add operation with another value of int type with metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a number -
sub
Description copied from class:LuaValue
-
sub
Description copied from class:LuaValue
Subtract: Perform numeric subtract operation with another value of double type with metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a number -
sub
Description copied from class:LuaValue
Subtract: Perform numeric subtract operation with another value of int type with metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a number -
subFrom
Description copied from class:LuaValue
Reverse-subtract: Perform numeric subtract operation from an int value with metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a number -
mul
Description copied from class:LuaValue
-
mul
Description copied from class:LuaValue
Multiply: Perform numeric multiply operation with another value of double type with metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a number -
mul
Description copied from class:LuaValue
Multiply: Perform numeric multiply operation with another value of int type with metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a number -
pow
Description copied from class:LuaValue
-
pow
Description copied from class:LuaValue
Raise to power: Raise this value to a power of double type with metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a number -
pow
Description copied from class:LuaValue
Raise to power: Raise this value to a power of int type with metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a number -
powWith
Description copied from class:LuaValue
Reverse-raise to power: Raise another value of double type to this power with metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a number -
powWith
Description copied from class:LuaValue
Reverse-raise to power: Raise another value of double type to this power with metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a number -
div
Description copied from class:LuaValue
-
div
Description copied from class:LuaValue
Divide: Perform numeric divide operation by another value of double type without metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a numberFor metatag processing
LuaValue.div(LuaValue)
must be used -
div
Description copied from class:LuaValue
Divide: Perform numeric divide operation by another value of int type without metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a numberFor metatag processing
LuaValue.div(LuaValue)
must be used -
divInto
Description copied from class:LuaValue
Reverse-divide: Perform numeric divide operation into another value with metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a number -
mod
Description copied from class:LuaValue
-
mod
Description copied from class:LuaValue
Modulo: Perform numeric modulo operation with another value of double type without metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a numberFor metatag processing
LuaValue.mod(LuaValue)
must be used -
mod
Description copied from class:LuaValue
Modulo: Perform numeric modulo operation with another value of int type without metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a numberFor metatag processing
LuaValue.mod(LuaValue)
must be used -
modFrom
Description copied from class:LuaValue
Reverse-modulo: Perform numeric modulo operation from another value with metatag processingthis
must derive fromLuaNumber
or derive fromLuaString
and be convertible to a number -
lt
Description copied from class:LuaValue
Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returningLuaValue
.To be comparable, both operands must derive from
LuaString
or both must derive fromLuaNumber
.- Overrides:
lt
in classLuaValue
- Parameters:
rhs
- The right-hand-side value to perform the comparison with- Returns:
LuaValue.TRUE
if(this < rhs)
,LuaValue.FALSE
if not, orLuaValue
if metatag processing occurs- See Also:
-
lt_b
Description copied from class:LuaValue
Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.To be comparable, both operands must derive from
LuaString
or both must derive fromLuaNumber
. -
lt_b
public boolean lt_b(int rhs) Description copied from class:LuaValue
Less than: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.To be comparable, this must derive from
LuaNumber
. -
lt_b
public boolean lt_b(double rhs) Description copied from class:LuaValue
Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.To be comparable, both operands must derive from
LuaString
or both must derive fromLuaNumber
. -
lteq
Description copied from class:LuaValue
Less than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returningLuaValue
.To be comparable, both operands must derive from
LuaString
or both must derive fromLuaNumber
.- Overrides:
lteq
in classLuaValue
- Parameters:
rhs
- The right-hand-side value to perform the comparison with- Returns:
LuaValue.TRUE
if(this <= rhs)
,LuaValue.FALSE
if not, orLuaValue
if metatag processing occurs- See Also:
-
lteq_b
Description copied from class:LuaValue
Less than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.To be comparable, both operands must derive from
LuaString
or both must derive fromLuaNumber
. -
lteq_b
public boolean lteq_b(int rhs) Description copied from class:LuaValue
Less than or equals: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.To be comparable, this must derive from
LuaNumber
. -
lteq_b
public boolean lteq_b(double rhs) Description copied from class:LuaValue
Less than or equals: Perform numeric comparison with another value of double type, including metatag processing, and returning java boolean.To be comparable, this must derive from
LuaNumber
. -
gt
Description copied from class:LuaValue
Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returningLuaValue
.To be comparable, both operands must derive from
LuaString
or both must derive fromLuaNumber
.- Overrides:
gt
in classLuaValue
- Parameters:
rhs
- The right-hand-side value to perform the comparison with- Returns:
LuaValue.TRUE
if(this > rhs)
,LuaValue.FALSE
if not, orLuaValue
if metatag processing occurs- See Also:
-
gt_b
Description copied from class:LuaValue
Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.To be comparable, both operands must derive from
LuaString
or both must derive fromLuaNumber
. -
gt_b
public boolean gt_b(int rhs) Description copied from class:LuaValue
Greater than: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.To be comparable, this must derive from
LuaNumber
. -
gt_b
public boolean gt_b(double rhs) Description copied from class:LuaValue
Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.To be comparable, both operands must derive from
LuaString
or both must derive fromLuaNumber
. -
gteq
Description copied from class:LuaValue
Greater than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returningLuaValue
.To be comparable, both operands must derive from
LuaString
or both must derive fromLuaNumber
.- Overrides:
gteq
in classLuaValue
- Parameters:
rhs
- The right-hand-side value to perform the comparison with- Returns:
LuaValue.TRUE
if(this >= rhs)
,LuaValue.FALSE
if not, orLuaValue
if metatag processing occurs- See Also:
-
gteq_b
Description copied from class:LuaValue
Greater than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.To be comparable, both operands must derive from
LuaString
or both must derive fromLuaNumber
. -
gteq_b
public boolean gteq_b(int rhs) Description copied from class:LuaValue
Greater than or equals: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.To be comparable, this must derive from
LuaNumber
. -
gteq_b
public boolean gteq_b(double rhs) Description copied from class:LuaValue
Greater than or equals: Perform numeric comparison with another value of double type, including metatag processing, and returning java boolean.To be comparable, this must derive from
LuaNumber
. -
concat
Description copied from class:LuaValue
-
concat
Description copied from class:LuaValue
-
concatTo
Description copied from class:LuaValue
Reverse-concatenation: concatenate this value onto another value known to be aLuaNumber
and return the result using rules of lua string concatenation including metatag processing.Only strings and numbers as represented can be concatenated, meaning each operand must derive from
LuaString
orLuaNumber
. -
concatTo
Description copied from class:LuaValue
Reverse-concatenation: concatenate this value onto another value known to be aLuaString
and return the result using rules of lua string concatenation including metatag processing.Only strings and numbers as represented can be concatenated, meaning each operand must derive from
LuaString
orLuaNumber
. -
strcmp
Description copied from class:LuaValue
Perform string comparison with another value of any type using string comparison based on byte values.Only strings can be compared, meaning each operand must derive from
LuaString
. -
strcmp
Description copied from class:LuaValue
-
checkint
public int checkint()Description copied from class:LuaValue
Check that the value is numeric, and convert and cast value to int, or throwLuaError
if not numericValues that are
LuaNumber
will be cast to int and may lose precision. Values that areLuaString
that can be converted to a number will be converted, then cast to int, so may also lose precision. -
checkinteger
Description copied from class:LuaValue
Check that the value is numeric, and convert and cast value to int, or throwLuaError
if not numericValues that are
LuaNumber
will be cast to int and may lose precision. Values that areLuaString
that can be converted to a number will be converted, then cast to int, so may also lose precision.- Overrides:
checkinteger
in classLuaValue
- Returns:
- value cast to a int and wrapped in
LuaInteger
if numeric - See Also:
-
checklong
public long checklong()Description copied from class:LuaValue
Check that the value is numeric, and convert and cast value to long, or throwLuaError
if not numericValues that are
LuaNumber
will be cast to long and may lose precision. Values that areLuaString
that can be converted to a number will be converted, then cast to long, so may also lose precision. -
checkdouble
public double checkdouble()Description copied from class:LuaValue
Check that the value is numeric and return the value as a double, or throwLuaError
if not numericValues that are
LuaNumber
and values that areLuaString
that can be converted to a number will be converted to double.- Overrides:
checkdouble
in classLuaValue
- Returns:
- value cast to a double if numeric
- See Also:
-
checknumber
Description copied from class:LuaValue
Check that the value is numeric, and return as a LuaNumber if so, or throwLuaError
Values that are
LuaString
that can be converted to a number will be converted and returned.- Overrides:
checknumber
in classLuaValue
- Returns:
- value as a
LuaNumber
if numeric - See Also:
-
checknumber
Description copied from class:LuaValue
Check that the value is numeric, and return as a LuaNumber if so, or throwLuaError
Values that are
LuaString
that can be converted to a number will be converted and returned.- Overrides:
checknumber
in classLuaValue
- Parameters:
msg
- String message to supply if conversion fails- Returns:
- value as a
LuaNumber
if numeric - See Also:
-
isnumber
public boolean isnumber()Description copied from class:LuaValue
Check ifthis
is anumber
-
isint
public boolean isint()Description copied from class:LuaValue
Check ifthis
is anumber
and is representable by java int without rounding or truncation -
islong
public boolean islong()Description copied from class:LuaValue
Check ifthis
is anumber
and is representable by java long without rounding or truncation -
tobyte
public byte tobyte()Description copied from class:LuaValue
Convert to byte if numeric, or 0 if not. -
tochar
public char tochar()Description copied from class:LuaValue
Convert to char if numeric, or 0 if not. -
todouble
public double todouble()Description copied from class:LuaValue
Convert to double if numeric, or 0 if not. -
tofloat
public float tofloat()Description copied from class:LuaValue
Convert to float if numeric, or 0 if not. -
toint
public int toint()Description copied from class:LuaValue
Convert to int if numeric, or 0 if not. -
tolong
public long tolong()Description copied from class:LuaValue
Convert to long if numeric, or 0 if not. -
toshort
public short toshort()Description copied from class:LuaValue
Convert to short if numeric, or 0 if not. -
optdouble
public double optdouble(double defval) Description copied from class:LuaValue
Check that optional argument is a number or string convertible to number and return as double -
optint
public int optint(int defval) Description copied from class:LuaValue
Check that optional argument is a number or string convertible to number and return as int -
optinteger
Description copied from class:LuaValue
Check that optional argument is a number or string convertible to number and return asLuaInteger
- Overrides:
optinteger
in classLuaValue
- Parameters:
defval
-LuaInteger
to return ifthis
is nil or none- Returns:
this
converted and wrapped inLuaInteger
if numeric,defval
if nil or none, throwsLuaError
otherwise- See Also:
-
optlong
public long optlong(long defval) Description copied from class:LuaValue
Check that optional argument is a number or string convertible to number and return as long -
optnumber
Description copied from class:LuaValue
Check that optional argument is a number or string convertible to number and return asLuaNumber
-
optstring
Description copied from class:LuaValue
Check that optional argument is a string or number and return asLuaString
-
tostring
Description copied from class:LuaValue
Conditionally convert to lua string without throwing errors.In lua all numbers are strings, so this function will return the
LuaValue
this
if it is a string or number, andLuaValue.NIL
for all other cases.This allows values to be tested for their "string-ness" without the penalty of throwing exceptions.
- Overrides:
tostring
in classLuaValue
- Returns:
this
if it is aLuaString
orLuaNumber
, otherwiseLuaValue.NIL
- See Also:
-
optjstring
Description copied from class:LuaValue
Check that optional argument is a string or number and return as Java String- Overrides:
optjstring
in classLuaValue
- Parameters:
defval
-LuaString
to return ifthis
is nil or none- Returns:
this
converted to String if a string or number,defval
if nil or none, throwsLuaError
if some other type- See Also:
-
strvalue
Description copied from class:LuaValue
-
substring
Take a substring using Java zero-based indexes for begin and end or range.- Parameters:
beginIndex
- The zero-based index of the first character to include.endIndex
- The zero-based index of position after the last character.- Returns:
- LuaString which is a substring whose first character is at offset beginIndex and extending for (endIndex - beginIndex ) characters.
-
hashCode
public int hashCode() -
hashCode
public static int hashCode(byte[] bytes, int offset, int length) Compute the hash code of a sequence of bytes within a byte array using lua's rules for string hashes. For long strings, not all bytes are hashed.- Parameters:
bytes
- byte array containing the bytes.offset
- offset into the hash for the first byte.length
- number of bytes starting with offset that are part of the string.- Returns:
- hash for the string defined by bytes, offset, and length.
-
equals
-
eq
Description copied from class:LuaValue
Equals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ
.- Overrides:
eq
in classLuaValue
- Parameters:
val
- The value to compare with.- Returns:
LuaValue.TRUE
if values are comparable and(this == rhs)
,LuaValue.FALSE
if comparable but not equal,LuaValue
if metatag processing occurs.- See Also:
-
eq_b
Description copied from class:LuaValue
Equals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ
, and return java boolean -
raweq
Description copied from class:LuaValue
Equals: Perform direct equality comparison with another value without metatag processing. -
raweq
Description copied from class:LuaValue
Equals: Perform direct equality comparison with aLuaString
value without metatag processing. -
equals
-
equals
public static boolean equals(byte[] a, int i, byte[] b, int j, int n) -
write
- Throws:
IOException
-
len
Description copied from class:LuaValue
Length operator: return lua length of object(#this)
including metatag processing as java int -
length
public int length()Description copied from class:LuaValue
Length operator: return lua length of object(#this)
including metatag processing as java int- Overrides:
length
in classLuaValue
- Returns:
- length as defined by the lua # operator
or metatag processing result converted to java int using
LuaValue.toint()
-
rawlen
public int rawlen()Description copied from class:LuaValue
Get raw length of table or string without metatag processing. -
luaByte
public int luaByte(int index) -
charAt
public int charAt(int index) -
checkjstring
Description copied from class:LuaValue
Convert this value to a Java String.The string representations here will roughly match what is produced by the C lua distribution, however hash codes have no relationship, and there may be differences in number formatting.
- Overrides:
checkjstring
in classLuaValue
- Returns:
- String representation of the value
- See Also:
-
checkstring
Description copied from class:LuaValue
Check that this is a lua string, or throwLuaError
if it is not.In lua all numbers are strings, so this will succeed for anything that derives from
LuaString
orLuaNumber
. Numbers will be converted toLuaString
.- Overrides:
checkstring
in classLuaValue
- Returns:
LuaString
representation of the value if it is aLuaString
orLuaNumber
- See Also:
-
toInputStream
Convert value to an input stream.- Returns:
InputStream
whose data matches the bytes in thisLuaString
-
copyInto
public void copyInto(int strOffset, byte[] bytes, int arrayOffset, int len) Copy the bytes of the string into the given byte array.- Parameters:
strOffset
- offset from which to copybytes
- destination byte arrayarrayOffset
- offset in destinationlen
- number of bytes to copy
-
indexOfAny
Java version of strpbrk - find index of any byte that in an accept string.- Parameters:
accept
-LuaString
containing characters to look for.- Returns:
- index of first match in the
accept
string, or -1 if not found.
-
indexOf
public int indexOf(byte b, int start) Find the index of a byte starting at a point in this string- Parameters:
b
- the byte to look forstart
- the first index in the string- Returns:
- index of first match found, or -1 if not found.
-
indexOf
Find the index of a string starting at a point in this string- Parameters:
s
- the string to search forstart
- the first index in the string- Returns:
- index of first match found, or -1 if not found.
-
lastIndexOf
Find the last index of a string in this string- Parameters:
s
- the string to search for- Returns:
- index of last match found, or -1 if not found.
-
decodeAsUtf8
Convert to Java String interpreting as utf8 characters.- Parameters:
bytes
- byte array in UTF8 encoding to convertoffset
- starting index in byte arraylength
- number of bytes to convert- Returns:
- Java String corresponding to the value of bytes interpreted using UTF8
- See Also:
-
lengthAsUtf8
public static int lengthAsUtf8(char[] chars) Count the number of bytes required to encode the string as UTF-8.- Parameters:
chars
- Array of unicode characters to be encoded as UTF-8- Returns:
- count of bytes needed to encode using UTF-8
- See Also:
-
encodeToUtf8
public static int encodeToUtf8(char[] chars, int nchars, byte[] bytes, int off) Encode the given Java string as UTF-8 bytes, writing the result to bytes starting at offset.The string should be measured first with lengthAsUtf8 to make sure the given byte array is large enough.
- Parameters:
chars
- Array of unicode characters to be encoded as UTF-8nchars
- Number of characters in the array to convert.bytes
- byte array to hold the resultoff
- offset into the byte array to start writing- Returns:
- number of bytes converted.
- See Also:
-
isValidUtf8
public boolean isValidUtf8()Check that a byte sequence is valid UTF-8- Returns:
- true if it is valid UTF-8, otherwise false
- See Also:
-
tonumber
convert to a number using baee 10 or base 16 if it starts with '0x', or NIL if it can't be converted -
tonumber
convert to a number using a supplied base, or NIL if it can't be converted- Parameters:
base
- the base to use, such as 10- Returns:
- IntValue, DoubleValue, or NIL depending on the content of the string.
- See Also:
-
scannumber
public double scannumber()Convert to a number in base 10, or base 16 if the string starts with '0x', or return Double.NaN if it cannot be converted to a number.- Returns:
- double value if conversion is valid, or Double.NaN if not
-
scannumber
public double scannumber(int base) Convert to a number in a base, or return Double.NaN if not a number.- Parameters:
base
- the base to use between 2 and 36- Returns:
- double value if conversion is valid, or Double.NaN if not
-
printToStream
Print the bytes of the LuaString to a PrintStream as if it were an ASCII string, quoting and escaping control characters.- Parameters:
ps
- PrintStream to print to.
-