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 LuaStrings 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.intThe number of bytes that comprise this stringintThe offset into the byte array, 0 means start at the first bytestatic LuaValueThe 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.intcharAt(int index) doubleCheck that the value is numeric and return the value as a double, or throwLuaErrorif not numericintcheckint()Check that the value is numeric, and convert and cast value to int, or throwLuaErrorif not numericCheck that the value is numeric, and convert and cast value to int, or throwLuaErrorif not numericConvert this value to a Java String.longCheck that the value is numeric, and convert and cast value to long, or throwLuaErrorif not numericCheck that the value is numeric, and return as a LuaNumber if so, or throwLuaErrorchecknumber(String msg) Check that the value is numeric, and return as a LuaNumber if so, or throwLuaErrorCheck that this is a lua string, or throwLuaErrorif it is not.Concatenate aBufferonto 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 aLuaNumberand return the result using rules of lua string concatenation including metatag processing.Reverse-concatenation: concatenate this value onto another value known to be aLuaStringand return the result using rules of lua string concatenation including metatag processing.voidcopyInto(int strOffset, byte[] bytes, int arrayOffset, int len) Copy the bytes of the string into the given byte array.static StringdecodeAsUtf8(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 intencodeToUtf8(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.booleanEquals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ, and return java booleanstatic booleanequals(byte[] a, int i, byte[] b, int j, int n) static booleanbooleanGet the metatable for thisLuaValueGreater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returningLuaValue.booleangt_b(double rhs) Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.booleangt_b(int rhs) Greater than: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.booleanGreater 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.booleangteq_b(double rhs) Greater than or equals: Perform numeric comparison with another value of double type, including metatag processing, and returning java boolean.booleangteq_b(int rhs) Greater than or equals: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.booleanGreater than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.inthashCode()static inthashCode(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.intindexOf(byte b, int start) Find the index of a byte starting at a point in this stringintFind the index of a string starting at a point in this stringintindexOfAny(LuaString accept) Java version of strpbrk - find index of any byte that in an accept string.booleanisint()Check ifthisis anumberand is representable by java int without rounding or truncationbooleanislong()Check ifthisis anumberand is representable by java long without rounding or truncationbooleanisnumber()Check ifthisis anumberbooleanisstring()Check ifthisis astringbooleanCheck that a byte sequence is valid UTF-8intFind the last index of a string in this stringlen()Length operator: return lua length of object(#this)including metatag processing as java intintlength()Length operator: return lua length of object(#this)including metatag processing as java intstatic intlengthAsUtf8(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.booleanlt_b(double rhs) Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.booleanlt_b(int rhs) Less than: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.booleanLess 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.booleanlteq_b(double rhs) Less than or equals: Perform numeric comparison with another value of double type, including metatag processing, and returning java boolean.booleanlteq_b(int rhs) Less than or equals: Perform numeric comparison with another value of int type, including metatag processing, and returning java boolean.booleanLess than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.intluaByte(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 operatordoubleoptdouble(double defval) Check that optional argument is a number or string convertible to number and return as doubleintoptint(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 asLuaIntegeroptjstring(String defval) Check that optional argument is a string or number and return as Java Stringlongoptlong(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 asLuaNumberCheck that optional argument is a string or number and return asLuaStringpow(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 processingvoidPrint the bytes of the LuaString to a PrintStream as if it were an ASCII string, quoting and escaping control characters.booleanEquals: Perform direct equality comparison with aLuaStringvalue without metatag processing.booleanEquals: Perform direct equality comparison with another value without metatag processing.intrawlen()Get raw length of table or string without metatag processing.voidread(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input) doubleConvert 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.doublescannumber(int base) Convert to a number in a base, or return Double.NaN if not a number.intPerform string comparison with another value known to be aLuaStringusing string comparison based on byte values.intPerform 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.bytetobyte()Convert to byte if numeric, or 0 if not.chartochar()Convert to char if numeric, or 0 if not.doubletodouble()Convert to double if numeric, or 0 if not.floattofloat()Convert to float if numeric, or 0 if not.Convert value to an input stream.inttoint()Convert to int if numeric, or 0 if not.Convert to human readable String for any type.longtolong()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 convertedshorttoshort()Convert to short if numeric, or 0 if not.tostring()Conditionally convert to lua string without throwing errors.inttype()Get the enumeration value for the type of this value.typename()Get the String name of the type of this value.static LuaStringvalueOf(byte[] bytes) Construct aLuaStringfor all the bytes in a byte array.static LuaStringvalueOf(byte[] bytes, int off, int len) Construct aLuaStringfor a portion of a byte array.static LuaStringvalueOf(char[] bytes) Construct aLuaStringusing the supplied characters as byte values.static LuaStringvalueOf(char[] bytes, int off, int len) Construct aLuaStringusing the supplied characters as byte values.static LuaStringGet aLuaStringinstance whose bytes match the supplied Java String using the UTF8 encoding.static LuaStringvalueUsing(byte[] bytes) Construct aLuaStringfor all the bytes in a byte array, possibly using the supplied array as the backing store.static LuaStringvalueUsing(byte[] bytes, int off, int len) Construct aLuaStringaround, possibly using the the supplied byte array as the backing store.voidwrite(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Output output) voidwrite(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, varargsOfMethods 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:
writein interfacecom.esotericsoftware.kryo.KryoSerializable
-
read
public void read(com.esotericsoftware.kryo.Kryo kryo, com.esotericsoftware.kryo.io.Input input) - Specified by:
readin interfacecom.esotericsoftware.kryo.KryoSerializable
-
valueOf
Get aLuaStringinstance whose bytes match the supplied Java String using the UTF8 encoding.- Parameters:
string- Java String containing characters to encode as UTF8- Returns:
LuaStringwith UTF8 bytes corresponding to the supplied String
-
valueOf
Construct aLuaStringfor 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:
LuaStringwrapping the byte buffer
-
valueUsing
Construct aLuaStringaround, 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:
LuaStringwrapping the byte buffer, or an equivalent string.
-
valueOf
Construct aLuaStringusing 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:
LuaStringwrapping a copy of the byte buffer
-
valueOf
Construct aLuaStringusing 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:
LuaStringwrapping a copy of the byte buffer
-
valueOf
Construct aLuaStringfor 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:
LuaStringwrapping the byte buffer
-
valueUsing
Construct aLuaStringfor 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:
LuaStringwrapping the byte buffer
-
isstring
public boolean isstring()Description copied from class:LuaValueCheck ifthisis astring -
getmetatable
Description copied from class:LuaValueGet the metatable for thisLuaValueFor
LuaTableandLuaUserdatainstances, the metatable returned is this instance metatable. For all other types, the class metatable value will be returned.- Overrides:
getmetatablein classLuaValue- Returns:
- metatable, or null if it there is none
- See Also:
-
type
public int type()Description copied from class:LuaValueGet the enumeration value for the type of this value.- Specified by:
typein 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:LuaValueGet the String name of the type of this value.- Specified by:
typenamein classLuaValue- Returns:
- name from type name list
LuaValue.TYPE_NAMEScorresponding to the type of this value: "nil", "boolean", "number", "string", "table", "function", "userdata", "thread" - See Also:
-
tojstring
Description copied from class:LuaValueConvert to human readable String for any type. -
neg
Description copied from class:LuaValueUnary minus: return negative value(-this)as defined by lua unary minus operator- Overrides:
negin classLuaValue- Returns:
- boolean inverse as
LuaBooleanif boolean or nil, numeric inverse asLuaNumberif numeric, or metatag processing result ifLuaValue.UNMmetatag is defined
-
add
Description copied from class:LuaValue -
add
Description copied from class:LuaValueAdd: Perform numeric add operation with another value of double type with metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a number -
add
Description copied from class:LuaValueAdd: Perform numeric add operation with another value of int type with metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a number -
sub
Description copied from class:LuaValue -
sub
Description copied from class:LuaValueSubtract: Perform numeric subtract operation with another value of double type with metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a number -
sub
Description copied from class:LuaValueSubtract: Perform numeric subtract operation with another value of int type with metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a number -
subFrom
Description copied from class:LuaValueReverse-subtract: Perform numeric subtract operation from an int value with metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a number -
mul
Description copied from class:LuaValue -
mul
Description copied from class:LuaValueMultiply: Perform numeric multiply operation with another value of double type with metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a number -
mul
Description copied from class:LuaValueMultiply: Perform numeric multiply operation with another value of int type with metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a number -
pow
Description copied from class:LuaValue -
pow
Description copied from class:LuaValueRaise to power: Raise this value to a power of double type with metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a number -
pow
Description copied from class:LuaValueRaise to power: Raise this value to a power of int type with metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a number -
powWith
Description copied from class:LuaValueReverse-raise to power: Raise another value of double type to this power with metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a number -
powWith
Description copied from class:LuaValueReverse-raise to power: Raise another value of double type to this power with metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a number -
div
Description copied from class:LuaValue -
div
Description copied from class:LuaValueDivide: Perform numeric divide operation by another value of double type without metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a numberFor metatag processing
LuaValue.div(LuaValue)must be used -
div
Description copied from class:LuaValueDivide: Perform numeric divide operation by another value of int type without metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a numberFor metatag processing
LuaValue.div(LuaValue)must be used -
divInto
Description copied from class:LuaValueReverse-divide: Perform numeric divide operation into another value with metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a number -
mod
Description copied from class:LuaValue -
mod
Description copied from class:LuaValueModulo: Perform numeric modulo operation with another value of double type without metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a numberFor metatag processing
LuaValue.mod(LuaValue)must be used -
mod
Description copied from class:LuaValueModulo: Perform numeric modulo operation with another value of int type without metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a numberFor metatag processing
LuaValue.mod(LuaValue)must be used -
modFrom
Description copied from class:LuaValueReverse-modulo: Perform numeric modulo operation from another value with metatag processingthismust derive fromLuaNumberor derive fromLuaStringand be convertible to a number -
lt
Description copied from class:LuaValueLess 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
LuaStringor both must derive fromLuaNumber.- Overrides:
ltin classLuaValue- Parameters:
rhs- The right-hand-side value to perform the comparison with- Returns:
LuaValue.TRUEif(this < rhs),LuaValue.FALSEif not, orLuaValueif metatag processing occurs- See Also:
-
lt_b
Description copied from class:LuaValueLess 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
LuaStringor both must derive fromLuaNumber. -
lt_b
public boolean lt_b(int rhs) Description copied from class:LuaValueLess 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:LuaValueLess 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
LuaStringor both must derive fromLuaNumber. -
lteq
Description copied from class:LuaValueLess 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
LuaStringor both must derive fromLuaNumber.- Overrides:
lteqin classLuaValue- Parameters:
rhs- The right-hand-side value to perform the comparison with- Returns:
LuaValue.TRUEif(this <= rhs),LuaValue.FALSEif not, orLuaValueif metatag processing occurs- See Also:
-
lteq_b
Description copied from class:LuaValueLess 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
LuaStringor both must derive fromLuaNumber. -
lteq_b
public boolean lteq_b(int rhs) Description copied from class:LuaValueLess 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:LuaValueLess 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:LuaValueGreater 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
LuaStringor both must derive fromLuaNumber.- Overrides:
gtin classLuaValue- Parameters:
rhs- The right-hand-side value to perform the comparison with- Returns:
LuaValue.TRUEif(this > rhs),LuaValue.FALSEif not, orLuaValueif metatag processing occurs- See Also:
-
gt_b
Description copied from class:LuaValueGreater 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
LuaStringor both must derive fromLuaNumber. -
gt_b
public boolean gt_b(int rhs) Description copied from class:LuaValueGreater 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:LuaValueGreater 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
LuaStringor both must derive fromLuaNumber. -
gteq
Description copied from class:LuaValueGreater 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
LuaStringor both must derive fromLuaNumber.- Overrides:
gteqin classLuaValue- Parameters:
rhs- The right-hand-side value to perform the comparison with- Returns:
LuaValue.TRUEif(this >= rhs),LuaValue.FALSEif not, orLuaValueif metatag processing occurs- See Also:
-
gteq_b
Description copied from class:LuaValueGreater 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
LuaStringor both must derive fromLuaNumber. -
gteq_b
public boolean gteq_b(int rhs) Description copied from class:LuaValueGreater 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:LuaValueGreater 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:LuaValueReverse-concatenation: concatenate this value onto another value known to be aLuaNumberand 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
LuaStringorLuaNumber. -
concatTo
Description copied from class:LuaValueReverse-concatenation: concatenate this value onto another value known to be aLuaStringand 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
LuaStringorLuaNumber. -
strcmp
Description copied from class:LuaValuePerform 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:LuaValueCheck that the value is numeric, and convert and cast value to int, or throwLuaErrorif not numericValues that are
LuaNumberwill be cast to int and may lose precision. Values that areLuaStringthat can be converted to a number will be converted, then cast to int, so may also lose precision. -
checkinteger
Description copied from class:LuaValueCheck that the value is numeric, and convert and cast value to int, or throwLuaErrorif not numericValues that are
LuaNumberwill be cast to int and may lose precision. Values that areLuaStringthat can be converted to a number will be converted, then cast to int, so may also lose precision.- Overrides:
checkintegerin classLuaValue- Returns:
- value cast to a int and wrapped in
LuaIntegerif numeric - See Also:
-
checklong
public long checklong()Description copied from class:LuaValueCheck that the value is numeric, and convert and cast value to long, or throwLuaErrorif not numericValues that are
LuaNumberwill be cast to long and may lose precision. Values that areLuaStringthat 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:LuaValueCheck that the value is numeric and return the value as a double, or throwLuaErrorif not numericValues that are
LuaNumberand values that areLuaStringthat can be converted to a number will be converted to double.- Overrides:
checkdoublein classLuaValue- Returns:
- value cast to a double if numeric
- See Also:
-
checknumber
Description copied from class:LuaValueCheck that the value is numeric, and return as a LuaNumber if so, or throwLuaErrorValues that are
LuaStringthat can be converted to a number will be converted and returned.- Overrides:
checknumberin classLuaValue- Returns:
- value as a
LuaNumberif numeric - See Also:
-
checknumber
Description copied from class:LuaValueCheck that the value is numeric, and return as a LuaNumber if so, or throwLuaErrorValues that are
LuaStringthat can be converted to a number will be converted and returned.- Overrides:
checknumberin classLuaValue- Parameters:
msg- String message to supply if conversion fails- Returns:
- value as a
LuaNumberif numeric - See Also:
-
isnumber
public boolean isnumber()Description copied from class:LuaValueCheck ifthisis anumber -
isint
public boolean isint()Description copied from class:LuaValueCheck ifthisis anumberand is representable by java int without rounding or truncation -
islong
public boolean islong()Description copied from class:LuaValueCheck ifthisis anumberand is representable by java long without rounding or truncation -
tobyte
public byte tobyte()Description copied from class:LuaValueConvert to byte if numeric, or 0 if not. -
tochar
public char tochar()Description copied from class:LuaValueConvert to char if numeric, or 0 if not. -
todouble
public double todouble()Description copied from class:LuaValueConvert to double if numeric, or 0 if not. -
tofloat
public float tofloat()Description copied from class:LuaValueConvert to float if numeric, or 0 if not. -
toint
public int toint()Description copied from class:LuaValueConvert to int if numeric, or 0 if not. -
tolong
public long tolong()Description copied from class:LuaValueConvert to long if numeric, or 0 if not. -
toshort
public short toshort()Description copied from class:LuaValueConvert to short if numeric, or 0 if not. -
optdouble
public double optdouble(double defval) Description copied from class:LuaValueCheck 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:LuaValueCheck that optional argument is a number or string convertible to number and return as int -
optinteger
Description copied from class:LuaValueCheck that optional argument is a number or string convertible to number and return asLuaInteger- Overrides:
optintegerin classLuaValue- Parameters:
defval-LuaIntegerto return ifthisis nil or none- Returns:
thisconverted and wrapped inLuaIntegerif numeric,defvalif nil or none, throwsLuaErrorotherwise- See Also:
-
optlong
public long optlong(long defval) Description copied from class:LuaValueCheck that optional argument is a number or string convertible to number and return as long -
optnumber
Description copied from class:LuaValueCheck that optional argument is a number or string convertible to number and return asLuaNumber -
optstring
Description copied from class:LuaValueCheck that optional argument is a string or number and return asLuaString -
tostring
Description copied from class:LuaValueConditionally convert to lua string without throwing errors.In lua all numbers are strings, so this function will return the
LuaValuethisif it is a string or number, andLuaValue.NILfor all other cases.This allows values to be tested for their "string-ness" without the penalty of throwing exceptions.
- Overrides:
tostringin classLuaValue- Returns:
thisif it is aLuaStringorLuaNumber, otherwiseLuaValue.NIL- See Also:
-
optjstring
Description copied from class:LuaValueCheck that optional argument is a string or number and return as Java String- Overrides:
optjstringin classLuaValue- Parameters:
defval-LuaStringto return ifthisis nil or none- Returns:
thisconverted to String if a string or number,defvalif nil or none, throwsLuaErrorif 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:LuaValueEquals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ.- Overrides:
eqin classLuaValue- Parameters:
val- The value to compare with.- Returns:
LuaValue.TRUEif values are comparable and(this == rhs),LuaValue.FALSEif comparable but not equal,LuaValueif metatag processing occurs.- See Also:
-
eq_b
Description copied from class:LuaValueEquals: Perform equality comparison with another value including metatag processing usingLuaValue.EQ, and return java boolean -
raweq
Description copied from class:LuaValueEquals: Perform direct equality comparison with another value without metatag processing. -
raweq
Description copied from class:LuaValueEquals: Perform direct equality comparison with aLuaStringvalue 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:LuaValueLength operator: return lua length of object(#this)including metatag processing as java int -
length
public int length()Description copied from class:LuaValueLength operator: return lua length of object(#this)including metatag processing as java int- Overrides:
lengthin 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:LuaValueGet 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:LuaValueConvert 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:
checkjstringin classLuaValue- Returns:
- String representation of the value
- See Also:
-
checkstring
Description copied from class:LuaValueCheck that this is a lua string, or throwLuaErrorif it is not.In lua all numbers are strings, so this will succeed for anything that derives from
LuaStringorLuaNumber. Numbers will be converted toLuaString.- Overrides:
checkstringin classLuaValue- Returns:
LuaStringrepresentation of the value if it is aLuaStringorLuaNumber- See Also:
-
toInputStream
Convert value to an input stream.- Returns:
InputStreamwhose 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-LuaStringcontaining characters to look for.- Returns:
- index of first match in the
acceptstring, 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.
-