org.luaj.vm2
Class LuaString

java.lang.Object
  extended by org.luaj.vm2.Varargs
      extended by org.luaj.vm2.LuaValue
          extended by org.luaj.vm2.LuaString

public class LuaString
extends LuaValue

Subclass of 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.

See Also:
LuaValue, LuaValue.valueOf(String), LuaValue.valueOf(byte[])

Field Summary
 byte[] m_bytes
          The bytes for the string.
 int m_length
          The number of bytes that comprise this string
 int m_offset
          The offset into the byte array, 0 means start at the first byte
static LuaValue s_metatable
          The singleton instance for string metatables that forwards to the string functions.
 
Fields inherited from class org.luaj.vm2.LuaValue
ADD, CALL, CONCAT, DIV, EMPTYSTRING, ENV, EQ, FALSE, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, 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
 LuaValue add(double rhs)
          Add: Perform numeric add operation with another value of double type with metatag processing
 LuaValue add(int rhs)
          Add: Perform numeric add operation with another value of int type with metatag processing
 LuaValue add(LuaValue rhs)
          Add: Perform numeric add operation with another value including metatag processing.
 int charAt(int index)
           
 double checkdouble()
          Check that the value is numeric and return the value as a double, or throw LuaError if not numeric
 int checkint()
          Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric
 LuaInteger checkinteger()
          Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric
 java.lang.String checkjstring()
          Convert this value to a Java String.
 long checklong()
          Check that the value is numeric, and convert and cast value to long, or throw LuaError if not numeric
 LuaNumber checknumber()
          Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError
 LuaNumber checknumber(java.lang.String msg)
          Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError
 LuaString checkstring()
          Check that this is a lua string, or throw LuaError if it is not.
 Buffer concat(Buffer rhs)
          Concatenate a Buffer onto this value and return the result using rules of lua string concatenation including metatag processing.
 LuaValue concat(LuaValue rhs)
          Concatenate another value onto this value and return the result using rules of lua string concatenation including metatag processing.
 LuaValue concatTo(LuaNumber lhs)
          Reverse-concatenation: concatenate this value onto another value known to be a LuaNumber and return the result using rules of lua string concatenation including metatag processing.
 LuaValue concatTo(LuaString lhs)
          Reverse-concatenation: concatenate this value onto another value known to be a LuaString 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 java.lang.String decodeAsUtf8(byte[] bytes, int offset, int length)
          Convert to Java String interpreting as utf8 characters.
 LuaValue div(double rhs)
          Divide: Perform numeric divide operation by another value of double type without metatag processing
 LuaValue div(int rhs)
          Divide: Perform numeric divide operation by another value of int type without metatag processing
 LuaValue div(LuaValue rhs)
          Divide: Perform numeric divide operation by another value of unknown type, including metatag processing.
 LuaValue divInto(double lhs)
          Reverse-divide: Perform numeric divide operation into another value with metatag processing
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.
 boolean eq_b(LuaValue val)
          Equals: Perform equality comparison with another value including metatag processing using LuaValue.EQ, and return java boolean
 LuaValue eq(LuaValue val)
          Equals: Perform equality comparison with another value including metatag processing using LuaValue.EQ.
static boolean equals(byte[] a, int i, byte[] b, int j, int n)
           
static boolean equals(LuaString a, int i, LuaString b, int j, int n)
           
 boolean equals(java.lang.Object o)
           
 LuaValue getmetatable()
          Get the metatable for this LuaValue
 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 gt_b(LuaValue rhs)
          Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.
 LuaValue gt(LuaValue rhs)
          Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.
 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 gteq_b(LuaValue rhs)
          Greater than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.
 LuaValue gteq(LuaValue rhs)
          Greater than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.
 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 string
 int indexOf(LuaString s, int start)
          Find the index of a string starting at a point in this string
 int indexOfAny(LuaString accept)
          Java version of strpbrk - find index of any byte that in an accept string.
 boolean isint()
          Check if this is a number and is representable by java int without rounding or truncation
 boolean islong()
          Check if this is a number and is representable by java long without rounding or truncation
 boolean isnumber()
          Check if this is a number
 boolean isstring()
          Check if this is a string
 boolean isValidUtf8()
          Check that a byte sequence is valid UTF-8
 int lastIndexOf(LuaString s)
          Find the last index of a string in this string
 LuaValue len()
          Length operator: return lua length of object (#this) including metatag processing as java int
 int length()
          Length operator: return lua length of object (#this) including metatag processing as java int
static int lengthAsUtf8(char[] chars)
          Count the number of bytes required to encode the string as UTF-8.
 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 lt_b(LuaValue rhs)
          Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.
 LuaValue lt(LuaValue rhs)
          Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.
 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 lteq_b(LuaValue rhs)
          Less than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning java boolean.
 LuaValue lteq(LuaValue rhs)
          Less than or equals: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.
 int luaByte(int index)
           
 LuaValue mod(double rhs)
          Modulo: Perform numeric modulo operation with another value of double type without metatag processing
 LuaValue mod(int rhs)
          Modulo: Perform numeric modulo operation with another value of int type without metatag processing
 LuaValue mod(LuaValue rhs)
          Modulo: Perform numeric modulo operation with another value of unknown type, including metatag processing.
 LuaValue modFrom(double lhs)
          Reverse-modulo: Perform numeric modulo operation from another value with metatag processing
 LuaValue mul(double rhs)
          Multiply: Perform numeric multiply operation with another value of double type with metatag processing
 LuaValue mul(int rhs)
          Multiply: Perform numeric multiply operation with another value of int type with metatag processing
 LuaValue mul(LuaValue rhs)
          Multiply: Perform numeric multiply operation with another value of unknown type, including metatag processing.
 LuaValue neg()
          Unary minus: return negative value (-this) as defined by lua unary minus operator
 double optdouble(double defval)
          Check that optional argument is a number or string convertible to number and return as double
 int optint(int defval)
          Check that optional argument is a number or string convertible to number and return as int
 LuaInteger optinteger(LuaInteger defval)
          Check that optional argument is a number or string convertible to number and return as LuaInteger
 java.lang.String optjstring(java.lang.String defval)
          Check that optional argument is a string or number and return as Java String
 long optlong(long defval)
          Check that optional argument is a number or string convertible to number and return as long
 LuaNumber optnumber(LuaNumber defval)
          Check that optional argument is a number or string convertible to number and return as LuaNumber
 LuaString optstring(LuaString defval)
          Check that optional argument is a string or number and return as LuaString
 LuaValue pow(double rhs)
          Raise to power: Raise this value to a power of double type with metatag processing
 LuaValue pow(int rhs)
          Raise to power: Raise this value to a power of int type with metatag processing
 LuaValue pow(LuaValue rhs)
          Raise to power: Raise this value to a power including metatag processing.
 LuaValue powWith(double lhs)
          Reverse-raise to power: Raise another value of double type to this power with metatag processing
 LuaValue powWith(int lhs)
          Reverse-raise to power: Raise another value of double type to this power with metatag processing
 void printToStream(java.io.PrintStream ps)
          Print the bytes of the LuaString to a PrintStream as if it were an ASCII string, quoting and escaping control characters.
 boolean raweq(LuaString s)
          Equals: Perform direct equality comparison with a LuaString value without metatag processing.
 boolean raweq(LuaValue val)
          Equals: Perform direct equality comparison with another value without metatag processing.
 int rawlen()
          Get raw length of table or string without metatag processing.
 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.
 double scannumber(int base)
          Convert to a number in a base, or return Double.NaN if not a number.
 int strcmp(LuaString rhs)
          Perform string comparison with another value known to be a LuaString using string comparison based on byte values.
 int strcmp(LuaValue lhs)
          Perform string comparison with another value of any type using string comparison based on byte values.
 LuaString strvalue()
          Convert this value to a string if it is a LuaString or LuaNumber, or throw a LuaError if it is not
 LuaValue sub(double rhs)
          Subtract: Perform numeric subtract operation with another value of double type with metatag processing
 LuaValue sub(int rhs)
          Subtract: Perform numeric subtract operation with another value of int type with metatag processing
 LuaValue sub(LuaValue rhs)
          Subtract: Perform numeric subtract operation with another value of unknown type, including metatag processing.
 LuaValue subFrom(double lhs)
          Reverse-subtract: Perform numeric subtract operation from an int value with metatag processing
 LuaString substring(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.
 java.io.InputStream toInputStream()
          Convert value to an input stream.
 int toint()
          Convert to int if numeric, or 0 if not.
 java.lang.String tojstring()
          Convert to human readable String for any type.
 long tolong()
          Convert to long if numeric, or 0 if not.
 LuaValue tonumber()
          convert to a number using baee 10 or base 16 if it starts with '0x', or NIL if it can't be converted
 LuaValue tonumber(int base)
          convert to a number using a supplied base, or NIL if it can't be converted
 short toshort()
          Convert to short if numeric, or 0 if not.
 LuaValue tostring()
          Conditionally convert to lua string without throwing errors.
 int type()
          Get the enumeration value for the type of this value.
 java.lang.String typename()
          Get the String name of the type of this value.
static LuaString valueOf(byte[] bytes)
          Construct a LuaString for all the bytes in a byte array.
static LuaString valueOf(byte[] bytes, int off, int len)
          Construct a LuaString for a portion of a byte array.
static LuaString valueOf(char[] bytes)
          Construct a LuaString using the supplied characters as byte values.
static LuaString valueOf(char[] bytes, int off, int len)
          Construct a LuaString using the supplied characters as byte values.
static LuaString valueOf(java.lang.String string)
          Get a LuaString instance whose bytes match the supplied Java String using the UTF8 encoding.
static LuaString valueUsing(byte[] bytes)
          Construct a LuaString 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 a LuaString around, possibly using the the supplied byte array as the backing store.
 void write(java.io.DataOutputStream writer, int i, int len)
           
 
Methods inherited from class org.luaj.vm2.LuaValue
and, arg, arg1, argerror, argerror, aritherror, aritherror, arithmt, arithmtwith, assert_, buffer, call, call, call, call, call, callmt, checkboolean, checkclosure, checkfunction, checkglobals, checkmetatag, checknotnil, checktable, checkthread, checkuserdata, checkuserdata, compareerror, compareerror, comparemt, concatmt, concatTo, eqmtcall, error, get, get, get, gettable, gt, gt, gteq, gteq, illegal, inext, initupvalue1, invoke, invoke, invoke, invoke, invoke, invoke, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, isboolean, isclosure, isfunction, isinttype, isnil, istable, isthread, isuserdata, isuserdata, isvalidkey, lenerror, listOf, listOf, load, lt, lt, lteq, lteq, metatableOf, metatag, method, method, method, method, method, method, narg, neq_b, neq, 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, settable, strongvalue, subargs, subFrom, tableOf, tableOf, tableOf, tableOf, tableOf, tableOf, tailcallOf, testfor_b, toboolean, toString, touserdata, touserdata, typerror, unimplemented, userdataOf, userdataOf, valueOf, valueOf, valueOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOf
 
Methods inherited from class org.luaj.vm2.Varargs
argcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, 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
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

s_metatable

public static LuaValue 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 final byte[] m_bytes
The 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 final int m_offset
The offset into the byte array, 0 means start at the first byte


m_length

public final int m_length
The number of bytes that comprise this string

Method Detail

valueOf

public static LuaString valueOf(java.lang.String string)
Get a LuaString 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

public static LuaString valueOf(byte[] bytes,
                                int off,
                                int len)
Construct a LuaString 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 buffer
off - offset into the byte buffer
len - length of the byte buffer
Returns:
LuaString wrapping the byte buffer

valueUsing

public static LuaString valueUsing(byte[] bytes,
                                   int off,
                                   int len)
Construct a LuaString 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

public static LuaString valueOf(char[] bytes)
Construct a LuaString 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

public static LuaString valueOf(char[] bytes,
                                int off,
                                int len)
Construct a LuaString 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

public static LuaString valueOf(byte[] bytes)
Construct a LuaString 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

public static LuaString valueUsing(byte[] bytes)
Construct a LuaString 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 if this is a string

Overrides:
isstring in class LuaValue
Returns:
true if this is a string, meaning derives from LuaString or LuaNumber, otherwise false
See Also:
LuaValue.tostring(), LuaValue.checkstring(), LuaValue.optstring(LuaString), LuaValue.TSTRING

getmetatable

public LuaValue getmetatable()
Description copied from class: LuaValue
Get the metatable for this LuaValue

For LuaTable and LuaUserdata instances, the metatable returned is this instance metatable. For all other types, the class metatable value will be returned.

Overrides:
getmetatable in class LuaValue
Returns:
metatable, or null if it there is none
See Also:
LuaBoolean.s_metatable, LuaNumber.s_metatable, LuaNil.s_metatable, LuaFunction.s_metatable, LuaThread.s_metatable

type

public int type()
Description copied from class: LuaValue
Get the enumeration value for the type of this value.

Specified by:
type in class LuaValue
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:
LuaValue.typename()

typename

public java.lang.String typename()
Description copied from class: LuaValue
Get the String name of the type of this value.

Specified by:
typename in class LuaValue
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:
LuaValue.type()

tojstring

public java.lang.String tojstring()
Description copied from class: LuaValue
Convert to human readable String for any type.

Overrides:
tojstring in class LuaValue
Returns:
String for use by human readers based on type.
See Also:
LuaValue.tostring(), LuaValue.optjstring(String), LuaValue.checkjstring(), LuaValue.isstring(), LuaValue.TSTRING

neg

public LuaValue neg()
Description copied from class: LuaValue
Unary minus: return negative value (-this) as defined by lua unary minus operator

Overrides:
neg in class LuaValue
Returns:
boolean inverse as LuaBoolean if boolean or nil, numeric inverse as LuaNumber if numeric, or metatag processing result if LuaValue.UNM metatag is defined

add

public LuaValue add(LuaValue rhs)
Description copied from class: LuaValue
Add: Perform numeric add operation with another value including metatag processing.

Each operand must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
add in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the add with
Returns:
value of (this + rhs) if both are numeric, or LuaValue if metatag processing occurs
See Also:
LuaValue.arithmt(LuaValue, LuaValue)

add

public LuaValue add(double rhs)
Description copied from class: LuaValue
Add: Perform numeric add operation with another value of double type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
add in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the add with
Returns:
value of (this + rhs) if this is numeric
See Also:
LuaValue.add(LuaValue)

add

public LuaValue add(int rhs)
Description copied from class: LuaValue
Add: Perform numeric add operation with another value of int type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
add in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the add with
Returns:
value of (this + rhs) if this is numeric
See Also:
LuaValue.add(LuaValue)

sub

public LuaValue sub(LuaValue rhs)
Description copied from class: LuaValue
Subtract: Perform numeric subtract operation with another value of unknown type, including metatag processing.

Each operand must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
sub in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the subtract with
Returns:
value of (this - rhs) if both are numeric, or LuaValue if metatag processing occurs
See Also:
LuaValue.arithmt(LuaValue, LuaValue)

sub

public LuaValue sub(double rhs)
Description copied from class: LuaValue
Subtract: Perform numeric subtract operation with another value of double type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
sub in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the subtract with
Returns:
value of (this - rhs) if this is numeric
See Also:
LuaValue.sub(LuaValue)

sub

public LuaValue sub(int rhs)
Description copied from class: LuaValue
Subtract: Perform numeric subtract operation with another value of int type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
sub in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the subtract with
Returns:
value of (this - rhs) if this is numeric
See Also:
LuaValue.sub(LuaValue)

subFrom

public LuaValue subFrom(double lhs)
Description copied from class: LuaValue
Reverse-subtract: Perform numeric subtract operation from an int value with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
subFrom in class LuaValue
Parameters:
lhs - The left-hand-side value from which to perform the subtraction
Returns:
value of (lhs - this) if this is numeric
See Also:
LuaValue.sub(LuaValue), LuaValue.sub(double), LuaValue.sub(int)

mul

public LuaValue mul(LuaValue rhs)
Description copied from class: LuaValue
Multiply: Perform numeric multiply operation with another value of unknown type, including metatag processing.

Each operand must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
mul in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the multiply with
Returns:
value of (this * rhs) if both are numeric, or LuaValue if metatag processing occurs
See Also:
LuaValue.arithmt(LuaValue, LuaValue)

mul

public LuaValue mul(double rhs)
Description copied from class: LuaValue
Multiply: Perform numeric multiply operation with another value of double type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
mul in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the multiply with
Returns:
value of (this * rhs) if this is numeric
See Also:
LuaValue.mul(LuaValue)

mul

public LuaValue mul(int rhs)
Description copied from class: LuaValue
Multiply: Perform numeric multiply operation with another value of int type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
mul in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the multiply with
Returns:
value of (this * rhs) if this is numeric
See Also:
LuaValue.mul(LuaValue)

pow

public LuaValue pow(LuaValue rhs)
Description copied from class: LuaValue
Raise to power: Raise this value to a power including metatag processing.

Each operand must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
pow in class LuaValue
Parameters:
rhs - The power to raise this value to
Returns:
value of (this ^ rhs) if both are numeric, or LuaValue if metatag processing occurs
See Also:
LuaValue.arithmt(LuaValue, LuaValue)

pow

public LuaValue pow(double rhs)
Description copied from class: LuaValue
Raise to power: Raise this value to a power of double type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
pow in class LuaValue
Parameters:
rhs - The power to raise this value to
Returns:
value of (this ^ rhs) if this is numeric
See Also:
LuaValue.pow(LuaValue)

pow

public LuaValue pow(int rhs)
Description copied from class: LuaValue
Raise to power: Raise this value to a power of int type with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
pow in class LuaValue
Parameters:
rhs - The power to raise this value to
Returns:
value of (this ^ rhs) if this is numeric
See Also:
LuaValue.pow(LuaValue)

powWith

public LuaValue powWith(double lhs)
Description copied from class: LuaValue
Reverse-raise to power: Raise another value of double type to this power with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
powWith in class LuaValue
Parameters:
lhs - The left-hand-side value which will be raised to this power
Returns:
value of (lhs ^ this) if this is numeric
See Also:
LuaValue.pow(LuaValue), LuaValue.pow(double), LuaValue.pow(int)

powWith

public LuaValue powWith(int lhs)
Description copied from class: LuaValue
Reverse-raise to power: Raise another value of double type to this power with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
powWith in class LuaValue
Parameters:
lhs - The left-hand-side value which will be raised to this power
Returns:
value of (lhs ^ this) if this is numeric
See Also:
LuaValue.pow(LuaValue), LuaValue.pow(double), LuaValue.pow(int)

div

public LuaValue div(LuaValue rhs)
Description copied from class: LuaValue
Divide: Perform numeric divide operation by another value of unknown type, including metatag processing.

Each operand must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
div in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the divulo with
Returns:
value of (this / rhs) if both are numeric, or LuaValue if metatag processing occurs
See Also:
LuaValue.arithmt(LuaValue, LuaValue)

div

public LuaValue div(double rhs)
Description copied from class: LuaValue
Divide: Perform numeric divide operation by another value of double type without metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

For metatag processing LuaValue.div(LuaValue) must be used

Overrides:
div in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the divulo with
Returns:
value of (this / rhs) if this is numeric
See Also:
LuaValue.div(LuaValue)

div

public LuaValue div(int rhs)
Description copied from class: LuaValue
Divide: Perform numeric divide operation by another value of int type without metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

For metatag processing LuaValue.div(LuaValue) must be used

Overrides:
div in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the divulo with
Returns:
value of (this / rhs) if this is numeric
See Also:
LuaValue.div(LuaValue)

divInto

public LuaValue divInto(double lhs)
Description copied from class: LuaValue
Reverse-divide: Perform numeric divide operation into another value with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
divInto in class LuaValue
Parameters:
lhs - The left-hand-side value which will be divided by this
Returns:
value of (lhs / this) if this is numeric
See Also:
LuaValue.div(LuaValue), LuaValue.div(double), LuaValue.div(int)

mod

public LuaValue mod(LuaValue rhs)
Description copied from class: LuaValue
Modulo: Perform numeric modulo operation with another value of unknown type, including metatag processing.

Each operand must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
mod in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the modulo with
Returns:
value of (this % rhs) if both are numeric, or LuaValue if metatag processing occurs
See Also:
LuaValue.arithmt(LuaValue, LuaValue)

mod

public LuaValue mod(double rhs)
Description copied from class: LuaValue
Modulo: Perform numeric modulo operation with another value of double type without metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

For metatag processing LuaValue.mod(LuaValue) must be used

Overrides:
mod in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the modulo with
Returns:
value of (this % rhs) if this is numeric
See Also:
LuaValue.mod(LuaValue)

mod

public LuaValue mod(int rhs)
Description copied from class: LuaValue
Modulo: Perform numeric modulo operation with another value of int type without metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

For metatag processing LuaValue.mod(LuaValue) must be used

Overrides:
mod in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the modulo with
Returns:
value of (this % rhs) if this is numeric
See Also:
LuaValue.mod(LuaValue)

modFrom

public LuaValue modFrom(double lhs)
Description copied from class: LuaValue
Reverse-modulo: Perform numeric modulo operation from another value with metatag processing

this must derive from LuaNumber or derive from LuaString and be convertible to a number

Overrides:
modFrom in class LuaValue
Parameters:
lhs - The left-hand-side value which will be modulo'ed by this
Returns:
value of (lhs % this) if this is numeric
See Also:
LuaValue.mod(LuaValue), LuaValue.mod(double), LuaValue.mod(int)

lt

public LuaValue lt(LuaValue rhs)
Description copied from class: LuaValue
Less than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.

To be comparable, both operands must derive from LuaString or both must derive from LuaNumber.

Overrides:
lt in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
LuaValue.TRUE if (this < rhs), LuaValue.FALSE if not, or LuaValue if metatag processing occurs
See Also:
LuaValue.gteq_b(LuaValue), LuaValue.comparemt(LuaValue, LuaValue)

lt_b

public boolean lt_b(LuaValue 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 from LuaNumber.

Overrides:
lt_b in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this < rhs), false if not, and boolean interpreation of result if metatag processing occurs.
See Also:
LuaValue.gteq(LuaValue), LuaValue.comparemt(LuaValue, LuaValue)

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.

Overrides:
lt_b in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this < rhs), false if not, and boolean interpreation of result if metatag processing occurs.
See Also:
LuaValue.gteq(int), LuaValue.comparemt(LuaValue, LuaValue)

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 from LuaNumber.

Overrides:
lt_b in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this < rhs), false if not, and boolean interpreation of result if metatag processing occurs.
See Also:
LuaValue.gteq(LuaValue), LuaValue.comparemt(LuaValue, LuaValue)

lteq

public LuaValue lteq(LuaValue rhs)
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 LuaValue.

To be comparable, both operands must derive from LuaString or both must derive from LuaNumber.

Overrides:
lteq in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
LuaValue.TRUE if (this <= rhs), LuaValue.FALSE if not, or LuaValue if metatag processing occurs
See Also:
LuaValue.gteq_b(LuaValue), LuaValue.comparemt(LuaValue, LuaValue)

lteq_b

public boolean lteq_b(LuaValue rhs)
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 from LuaNumber.

Overrides:
lteq_b in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this <= rhs), false if not, and boolean interpreation of result if metatag processing occurs.
See Also:
LuaValue.gteq(LuaValue), LuaValue.comparemt(LuaValue, LuaValue)

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.

Overrides:
lteq_b in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this <= rhs), false if not, and boolean interpreation of result if metatag processing occurs.
See Also:
LuaValue.gteq(int), LuaValue.comparemt(LuaValue, LuaValue)

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.

Overrides:
lteq_b in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this <= rhs), false if not, and boolean interpreation of result if metatag processing occurs.
See Also:
LuaValue.gteq(double), LuaValue.comparemt(LuaValue, LuaValue)

gt

public LuaValue gt(LuaValue rhs)
Description copied from class: LuaValue
Greater than: Perform numeric or string comparison with another value of unknown type, including metatag processing, and returning LuaValue.

To be comparable, both operands must derive from LuaString or both must derive from LuaNumber.

Overrides:
gt in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
LuaValue.TRUE if (this > rhs), LuaValue.FALSE if not, or LuaValue if metatag processing occurs
See Also:
LuaValue.gteq_b(LuaValue), LuaValue.comparemt(LuaValue, LuaValue)

gt_b

public boolean gt_b(LuaValue 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 from LuaNumber.

Overrides:
gt_b in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this > rhs), false if not, and boolean interpreation of result if metatag processing occurs.
See Also:
LuaValue.gteq(LuaValue), LuaValue.comparemt(LuaValue, LuaValue)

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.

Overrides:
gt_b in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this > rhs), false if not, and boolean interpreation of result if metatag processing occurs.
See Also:
LuaValue.gteq(int), LuaValue.comparemt(LuaValue, LuaValue)

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 from LuaNumber.

Overrides:
gt_b in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this > rhs), false if not, and boolean interpreation of result if metatag processing occurs.
See Also:
LuaValue.gteq(LuaValue), LuaValue.comparemt(LuaValue, LuaValue)

gteq

public LuaValue gteq(LuaValue rhs)
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 LuaValue.

To be comparable, both operands must derive from LuaString or both must derive from LuaNumber.

Overrides:
gteq in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
LuaValue.TRUE if (this >= rhs), LuaValue.FALSE if not, or LuaValue if metatag processing occurs
See Also:
LuaValue.gteq_b(LuaValue), LuaValue.comparemt(LuaValue, LuaValue)

gteq_b

public boolean gteq_b(LuaValue rhs)
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 from LuaNumber.

Overrides:
gteq_b in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this >= rhs), false if not, and boolean interpreation of result if metatag processing occurs.
See Also:
LuaValue.gteq(LuaValue), LuaValue.comparemt(LuaValue, LuaValue)

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.

Overrides:
gteq_b in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this >= rhs), false if not, and boolean interpreation of result if metatag processing occurs.
See Also:
LuaValue.gteq(int), LuaValue.comparemt(LuaValue, LuaValue)

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.

Overrides:
gteq_b in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
true if (this >= rhs), false if not, and boolean interpreation of result if metatag processing occurs.
See Also:
LuaValue.gteq(double), LuaValue.comparemt(LuaValue, LuaValue)

concat

public LuaValue concat(LuaValue rhs)
Description copied from class: LuaValue
Concatenate another value onto this value 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 or LuaNumber.

Overrides:
concat in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the operation with
Returns:
LuaValue resulting from concatenation of (this .. rhs)

concat

public Buffer concat(Buffer rhs)
Description copied from class: LuaValue
Concatenate a Buffer onto this value 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 or LuaNumber.

Overrides:
concat in class LuaValue
Parameters:
rhs - The right-hand-side Buffer to perform the operation with
Returns:
LuaString resulting from concatenation of (this .. rhs)

concatTo

public LuaValue concatTo(LuaNumber lhs)
Description copied from class: LuaValue
Reverse-concatenation: concatenate this value onto another value known to be a LuaNumber 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 or LuaNumber.

Overrides:
concatTo in class LuaValue
Parameters:
lhs - The left-hand-side value onto which this will be concatenated
Returns:
LuaValue resulting from concatenation of (lhs .. this)
See Also:
LuaValue.concat(LuaValue)

concatTo

public LuaValue concatTo(LuaString lhs)
Description copied from class: LuaValue
Reverse-concatenation: concatenate this value onto another value known to be a LuaString 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 or LuaNumber.

Overrides:
concatTo in class LuaValue
Parameters:
lhs - The left-hand-side value onto which this will be concatenated
Returns:
LuaValue resulting from concatenation of (lhs .. this)
See Also:
LuaValue.concat(LuaValue)

strcmp

public int strcmp(LuaValue lhs)
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.

Overrides:
strcmp in class LuaValue
Parameters:
lhs - The right-hand-side value to perform the comparison with
Returns:
int < 0 for (this < rhs), int > 0 for (this > rhs), or 0 when same string.

strcmp

public int strcmp(LuaString rhs)
Description copied from class: LuaValue
Perform string comparison with another value known to be a LuaString using string comparison based on byte values.

Only strings can be compared, meaning each operand must derive from LuaString.

Overrides:
strcmp in class LuaValue
Parameters:
rhs - The right-hand-side value to perform the comparison with
Returns:
int < 0 for (this < rhs), int > 0 for (this > rhs), or 0 when same string.

checkint

public int checkint()
Description copied from class: LuaValue
Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric

Values that are LuaNumber will be cast to int and may lose precision. Values that are LuaString that can be converted to a number will be converted, then cast to int, so may also lose precision.

Overrides:
checkint in class LuaValue
Returns:
value cast to a int if numeric
See Also:
LuaValue.checkinteger(), LuaValue.checklong(), LuaValue.checkdouble(), LuaValue.optint(int), LuaValue.TNUMBER

checkinteger

public LuaInteger checkinteger()
Description copied from class: LuaValue
Check that the value is numeric, and convert and cast value to int, or throw LuaError if not numeric

Values that are LuaNumber will be cast to int and may lose precision. Values that are LuaString that can be converted to a number will be converted, then cast to int, so may also lose precision.

Overrides:
checkinteger in class LuaValue
Returns:
value cast to a int and wrapped in LuaInteger if numeric
See Also:
LuaValue.checkint(), LuaValue.checklong(), LuaValue.checkdouble(), LuaValue.optinteger(LuaInteger), LuaValue.TNUMBER

checklong

public long checklong()
Description copied from class: LuaValue
Check that the value is numeric, and convert and cast value to long, or throw LuaError if not numeric

Values that are LuaNumber will be cast to long and may lose precision. Values that are LuaString that can be converted to a number will be converted, then cast to long, so may also lose precision.

Overrides:
checklong in class LuaValue
Returns:
value cast to a long if numeric
See Also:
LuaValue.checkint(), LuaValue.checkinteger(), LuaValue.checkdouble(), LuaValue.optlong(long), LuaValue.TNUMBER

checkdouble

public double checkdouble()
Description copied from class: LuaValue
Check that the value is numeric and return the value as a double, or throw LuaError if not numeric

Values that are LuaNumber and values that are LuaString that can be converted to a number will be converted to double.

Overrides:
checkdouble in class LuaValue
Returns:
value cast to a double if numeric
See Also:
LuaValue.checkint(), LuaValue.checkinteger(), LuaValue.checklong(), LuaValue.optdouble(double), LuaValue.TNUMBER

checknumber

public LuaNumber checknumber()
Description copied from class: LuaValue
Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError

Values that are LuaString that can be converted to a number will be converted and returned.

Overrides:
checknumber in class LuaValue
Returns:
value as a LuaNumber if numeric
See Also:
LuaValue.checkint(), LuaValue.checkinteger(), LuaValue.checkdouble(), LuaValue.checklong(), LuaValue.optnumber(LuaNumber), LuaValue.TNUMBER

checknumber

public LuaNumber checknumber(java.lang.String msg)
Description copied from class: LuaValue
Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError

Values that are LuaString that can be converted to a number will be converted and returned.

Overrides:
checknumber in class LuaValue
Parameters:
msg - String message to supply if conversion fails
Returns:
value as a LuaNumber if numeric
See Also:
LuaValue.checkint(), LuaValue.checkinteger(), LuaValue.checkdouble(), LuaValue.checklong(), LuaValue.optnumber(LuaNumber), LuaValue.TNUMBER

isnumber

public boolean isnumber()
Description copied from class: LuaValue
Check if this is a number

Overrides:
isnumber in class LuaValue
Returns:
true if this is a number, meaning derives from LuaNumber or derives from LuaString and is convertible to a number, otherwise false
See Also:
LuaValue.tonumber(), LuaValue.checknumber(), LuaValue.optnumber(LuaNumber), LuaValue.TNUMBER

isint

public boolean isint()
Description copied from class: LuaValue
Check if this is a number and is representable by java int without rounding or truncation

Overrides:
isint in class LuaValue
Returns:
true if this is a number meaning derives from LuaNumber or derives from LuaString and is convertible to a number, and can be represented by int, otherwise false
See Also:
LuaValue.isinttype(), LuaValue.islong(), LuaValue.tonumber(), LuaValue.checkint(), LuaValue.optint(int), LuaValue.TNUMBER

islong

public boolean islong()
Description copied from class: LuaValue
Check if this is a number and is representable by java long without rounding or truncation

Overrides:
islong in class LuaValue
Returns:
true if this is a number meaning derives from LuaNumber or derives from LuaString and is convertible to a number, and can be represented by long, otherwise false
See Also:
LuaValue.tonumber(), LuaValue.checklong(), LuaValue.optlong(long), LuaValue.TNUMBER

tobyte

public byte tobyte()
Description copied from class: LuaValue
Convert to byte if numeric, or 0 if not.

Overrides:
tobyte in class LuaValue
Returns:
Value cast to byte if number or string convertible to number, otherwise 0
See Also:
LuaValue.toint(), LuaValue.todouble(), LuaValue.checknumber(), LuaValue.isnumber(), LuaValue.TNUMBER

tochar

public char tochar()
Description copied from class: LuaValue
Convert to char if numeric, or 0 if not.

Overrides:
tochar in class LuaValue
Returns:
Value cast to char if number or string convertible to number, otherwise 0
See Also:
LuaValue.toint(), LuaValue.todouble(), LuaValue.checknumber(), LuaValue.isnumber(), LuaValue.TNUMBER

todouble

public double todouble()
Description copied from class: LuaValue
Convert to double if numeric, or 0 if not.

Overrides:
todouble in class LuaValue
Returns:
Value cast to double if number or string convertible to number, otherwise 0
See Also:
LuaValue.toint(), LuaValue.tobyte(), LuaValue.tochar(), LuaValue.toshort(), LuaValue.tolong(), LuaValue.tofloat(), LuaValue.optdouble(double), LuaValue.checknumber(), LuaValue.isnumber(), LuaValue.TNUMBER

tofloat

public float tofloat()
Description copied from class: LuaValue
Convert to float if numeric, or 0 if not.

Overrides:
tofloat in class LuaValue
Returns:
Value cast to float if number or string convertible to number, otherwise 0
See Also:
LuaValue.toint(), LuaValue.todouble(), LuaValue.checknumber(), LuaValue.isnumber(), LuaValue.TNUMBER

toint

public int toint()
Description copied from class: LuaValue
Convert to int if numeric, or 0 if not.

Overrides:
toint in class LuaValue
Returns:
Value cast to int if number or string convertible to number, otherwise 0
See Also:
LuaValue.tobyte(), LuaValue.tochar(), LuaValue.toshort(), LuaValue.tolong(), LuaValue.tofloat(), LuaValue.todouble(), LuaValue.optint(int), LuaValue.checknumber(), LuaValue.isnumber(), LuaValue.TNUMBER

tolong

public long tolong()
Description copied from class: LuaValue
Convert to long if numeric, or 0 if not.

Overrides:
tolong in class LuaValue
Returns:
Value cast to long if number or string convertible to number, otherwise 0
See Also:
LuaValue.isint(), LuaValue.isinttype(), LuaValue.toint(), LuaValue.todouble(), LuaValue.optlong(long), LuaValue.checknumber(), LuaValue.isnumber(), LuaValue.TNUMBER

toshort

public short toshort()
Description copied from class: LuaValue
Convert to short if numeric, or 0 if not.

Overrides:
toshort in class LuaValue
Returns:
Value cast to short if number or string convertible to number, otherwise 0
See Also:
LuaValue.toint(), LuaValue.todouble(), LuaValue.checknumber(), LuaValue.isnumber(), LuaValue.TNUMBER

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

Overrides:
optdouble in class LuaValue
Parameters:
defval - double to return if this is nil or none
Returns:
this cast to double if numeric, defval if nil or none, throws LuaError otherwise
See Also:
LuaValue.optint(int), LuaValue.optinteger(LuaInteger), LuaValue.checkdouble(), LuaValue.todouble(), LuaValue.tonumber(), LuaValue.isnumber(), LuaValue.TNUMBER

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

Overrides:
optint in class LuaValue
Parameters:
defval - int to return if this is nil or none
Returns:
this cast to int if numeric, defval if nil or none, throws LuaError otherwise
See Also:
LuaValue.optdouble(double), LuaValue.optlong(long), LuaValue.optinteger(LuaInteger), LuaValue.checkint(), LuaValue.toint(), LuaValue.tonumber(), LuaValue.isnumber(), LuaValue.TNUMBER

optinteger

public LuaInteger optinteger(LuaInteger defval)
Description copied from class: LuaValue
Check that optional argument is a number or string convertible to number and return as LuaInteger

Overrides:
optinteger in class LuaValue
Parameters:
defval - LuaInteger to return if this is nil or none
Returns:
this converted and wrapped in LuaInteger if numeric, defval if nil or none, throws LuaError otherwise
See Also:
LuaValue.optdouble(double), LuaValue.optint(int), LuaValue.checkint(), LuaValue.toint(), LuaValue.tonumber(), LuaValue.isnumber(), LuaValue.TNUMBER

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

Overrides:
optlong in class LuaValue
Parameters:
defval - long to return if this is nil or none
Returns:
this cast to long if numeric, defval if nil or none, throws LuaError otherwise
See Also:
LuaValue.optdouble(double), LuaValue.optint(int), LuaValue.checkint(), LuaValue.toint(), LuaValue.tonumber(), LuaValue.isnumber(), LuaValue.TNUMBER

optnumber

public LuaNumber optnumber(LuaNumber defval)
Description copied from class: LuaValue
Check that optional argument is a number or string convertible to number and return as LuaNumber

Overrides:
optnumber in class LuaValue
Parameters:
defval - LuaNumber to return if this is nil or none
Returns:
this cast to LuaNumber if numeric, defval if nil or none, throws LuaError otherwise
See Also:
LuaValue.optdouble(double), LuaValue.optlong(long), LuaValue.optint(int), LuaValue.checkint(), LuaValue.toint(), LuaValue.tonumber(), LuaValue.isnumber(), LuaValue.TNUMBER

optstring

public LuaString optstring(LuaString defval)
Description copied from class: LuaValue
Check that optional argument is a string or number and return as LuaString

Overrides:
optstring in class LuaValue
Parameters:
defval - LuaString to return if this is nil or none
Returns:
this converted to LuaString if a string or number, defval if nil or none, throws LuaError if some other type
See Also:
LuaValue.tojstring(), LuaValue.optjstring(String), LuaValue.checkstring(), LuaValue.toString(), LuaValue.TSTRING

tostring

public LuaValue 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, and LuaValue.NIL for all other cases.

This allows values to be tested for their "string-ness" without the penalty of throwing exceptions.

Overrides:
tostring in class LuaValue
Returns:
this if it is a LuaString or LuaNumber, otherwise LuaValue.NIL
See Also:
LuaValue.tonumber(), LuaValue.tojstring(), LuaValue.optstring(LuaString), LuaValue.checkstring(), LuaValue.toString()

optjstring

public java.lang.String optjstring(java.lang.String defval)
Description copied from class: LuaValue
Check that optional argument is a string or number and return as Java String

Overrides:
optjstring in class LuaValue
Parameters:
defval - LuaString to return if this is nil or none
Returns:
this converted to String if a string or number, defval if nil or none, throws LuaError if some other type
See Also:
LuaValue.tojstring(), LuaValue.optstring(LuaString), LuaValue.checkjstring(), LuaValue.toString(), LuaValue.TSTRING

strvalue

public LuaString strvalue()
Description copied from class: LuaValue
Convert this value to a string if it is a LuaString or LuaNumber, or throw a LuaError if it is not

Overrides:
strvalue in class LuaValue
Returns:
LuaString corresponding to the value if a string or number

substring

public LuaString substring(int beginIndex,
                           int endIndex)
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()
Overrides:
hashCode in class java.lang.Object

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

public boolean equals(java.lang.Object o)
Overrides:
equals in class LuaValue

eq

public LuaValue eq(LuaValue val)
Description copied from class: LuaValue
Equals: Perform equality comparison with another value including metatag processing using LuaValue.EQ.

Overrides:
eq in class LuaValue
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:
LuaValue.eq_b(LuaValue), LuaValue.raweq(LuaValue), LuaValue.neq(LuaValue), LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue), LuaValue.EQ

eq_b

public boolean eq_b(LuaValue val)
Description copied from class: LuaValue
Equals: Perform equality comparison with another value including metatag processing using LuaValue.EQ, and return java boolean

Overrides:
eq_b in class LuaValue
Parameters:
val - The value to compare with.
Returns:
true if values are comparable and (this == rhs), false if comparable but not equal, result converted to java boolean if metatag processing occurs.
See Also:
LuaValue.eq(LuaValue), LuaValue.raweq(LuaValue), LuaValue.neq_b(LuaValue), LuaValue.eqmtcall(LuaValue, LuaValue, LuaValue, LuaValue), LuaValue.EQ

raweq

public boolean raweq(LuaValue val)
Description copied from class: LuaValue
Equals: Perform direct equality comparison with another value without metatag processing.

Overrides:
raweq in class LuaValue
Parameters:
val - The value to compare with.
Returns:
true if (this == rhs), false otherwise
See Also:
LuaValue.eq(LuaValue), LuaValue.raweq(LuaUserdata), LuaValue.raweq(LuaString), LuaValue.raweq(double), LuaValue.raweq(int), LuaValue.EQ

raweq

public boolean raweq(LuaString s)
Description copied from class: LuaValue
Equals: Perform direct equality comparison with a LuaString value without metatag processing.

Overrides:
raweq in class LuaValue
Parameters:
s - The LuaString to compare with.
Returns:
true if this is a LuaString and their byte sequences match, otherwise false

equals

public static boolean equals(LuaString a,
                             int i,
                             LuaString b,
                             int j,
                             int n)

equals

public static boolean equals(byte[] a,
                             int i,
                             byte[] b,
                             int j,
                             int n)

write

public void write(java.io.DataOutputStream writer,
                  int i,
                  int len)
           throws java.io.IOException
Throws:
java.io.IOException

len

public LuaValue len()
Description copied from class: LuaValue
Length operator: return lua length of object (#this) including metatag processing as java int

Overrides:
len in class LuaValue
Returns:
length as defined by the lua # operator or metatag processing result

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 class LuaValue
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.

Overrides:
rawlen in class LuaValue
Returns:
the length of the table or string.

luaByte

public int luaByte(int index)

charAt

public int charAt(int index)

checkjstring

public java.lang.String 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 class LuaValue
Returns:
String representation of the value
See Also:
LuaValue.checkstring(), LuaValue.optjstring(String), LuaValue.tojstring(), LuaValue.isstring(), LuaValue.TSTRING

checkstring

public LuaString checkstring()
Description copied from class: LuaValue
Check that this is a lua string, or throw LuaError if it is not.

In lua all numbers are strings, so this will succeed for anything that derives from LuaString or LuaNumber. Numbers will be converted to LuaString.

Overrides:
checkstring in class LuaValue
Returns:
LuaString representation of the value if it is a LuaString or LuaNumber
See Also:
LuaValue.checkjstring(), LuaValue.optstring(LuaString), LuaValue.tostring(), LuaValue.isstring(), LuaValue.TSTRING

toInputStream

public java.io.InputStream toInputStream()
Convert value to an input stream.

Returns:
InputStream whose data matches the bytes in this LuaString

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 copy
bytes - destination byte array
arrayOffset - offset in destination
len - number of bytes to copy

indexOfAny

public int indexOfAny(LuaString accept)
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 for
start - the first index in the string
Returns:
index of first match found, or -1 if not found.

indexOf

public int indexOf(LuaString s,
                   int start)
Find the index of a string starting at a point in this string

Parameters:
s - the string to search for
start - the first index in the string
Returns:
index of first match found, or -1 if not found.

lastIndexOf

public int lastIndexOf(LuaString s)
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

public static java.lang.String decodeAsUtf8(byte[] bytes,
                                            int offset,
                                            int length)
Convert to Java String interpreting as utf8 characters.

Parameters:
bytes - byte array in UTF8 encoding to convert
offset - starting index in byte array
length - number of bytes to convert
Returns:
Java String corresponding to the value of bytes interpreted using UTF8
See Also:
lengthAsUtf8(char[]), encodeToUtf8(char[], int, byte[], int), isValidUtf8()

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(char[], int, byte[], int), decodeAsUtf8(byte[], int, int), isValidUtf8()

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-8
nchars - Number of characters in the array to convert.
bytes - byte array to hold the result
off - offset into the byte array to start writing
Returns:
number of bytes converted.
See Also:
lengthAsUtf8(char[]), decodeAsUtf8(byte[], int, int), isValidUtf8()

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:
lengthAsUtf8(char[]), encodeToUtf8(char[], int, byte[], int), decodeAsUtf8(byte[], int, int)

tonumber

public LuaValue tonumber()
convert to a number using baee 10 or base 16 if it starts with '0x', or NIL if it can't be converted

Overrides:
tonumber in class LuaValue
Returns:
IntValue, DoubleValue, or NIL depending on the content of the string.
See Also:
LuaValue.tonumber()

tonumber

public LuaValue tonumber(int base)
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:
LuaValue.tonumber()

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

public void printToStream(java.io.PrintStream ps)
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.


Copyright © 2007-2015 Luaj.org. All Rights Reserved.