|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.luaj.vm2.Varargs org.luaj.vm2.LuaValue org.luaj.vm2.LuaNumber
public abstract class LuaNumber
Base class for representing numbers as lua values directly.
The main subclasses are LuaInteger
which holds values that fit in a java int,
and LuaDouble
which holds all other number values.
LuaInteger
,
LuaDouble
,
LuaValue
Field Summary | |
---|---|
static LuaValue |
s_metatable
Shared static metatable for all number values represented in lua. |
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 |
Constructor Summary | |
---|---|
LuaNumber()
|
Method Summary | |
---|---|
LuaNumber |
checknumber()
Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError |
LuaNumber |
checknumber(java.lang.String errmsg)
Check that the value is numeric, and return as a LuaNumber if so, or throw LuaError |
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. |
LuaValue |
getmetatable()
Get the metatable for this LuaValue |
boolean |
isnumber()
Check if this is a number |
boolean |
isstring()
Check if this is a string |
LuaNumber |
optnumber(LuaNumber defval)
Check that optional argument is a number or string convertible to number and return as LuaNumber |
LuaValue |
tonumber()
Conditionally convert to lua number 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. |
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, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static LuaValue s_metatable
Constructor Detail |
---|
public LuaNumber()
Method Detail |
---|
public int type()
LuaValue
type
in class LuaValue
LuaValue.TNIL
,
LuaValue.TBOOLEAN
,
LuaValue.TNUMBER
,
LuaValue.TSTRING
,
LuaValue.TTABLE
,
LuaValue.TFUNCTION
,
LuaValue.TUSERDATA
,
LuaValue.TTHREAD
LuaValue.typename()
public java.lang.String typename()
LuaValue
typename
in class LuaValue
LuaValue.TYPE_NAMES
corresponding to the type of this value:
"nil", "boolean", "number", "string",
"table", "function", "userdata", "thread"LuaValue.type()
public LuaNumber checknumber()
LuaValue
LuaError
Values that are LuaString
that can be converted to a number will be converted and returned.
checknumber
in class LuaValue
LuaNumber
if numericLuaValue.checkint()
,
LuaValue.checkinteger()
,
LuaValue.checkdouble()
,
LuaValue.checklong()
,
LuaValue.optnumber(LuaNumber)
,
LuaValue.TNUMBER
public LuaNumber checknumber(java.lang.String errmsg)
LuaValue
LuaError
Values that are LuaString
that can be converted to a number will be converted and returned.
checknumber
in class LuaValue
errmsg
- String message to supply if conversion fails
LuaNumber
if numericLuaValue.checkint()
,
LuaValue.checkinteger()
,
LuaValue.checkdouble()
,
LuaValue.checklong()
,
LuaValue.optnumber(LuaNumber)
,
LuaValue.TNUMBER
public LuaNumber optnumber(LuaNumber defval)
LuaValue
LuaNumber
optnumber
in class LuaValue
defval
- LuaNumber
to return if this
is nil or none
this
cast to LuaNumber
if numeric,
defval
if nil or none,
throws LuaError
otherwiseLuaValue.optdouble(double)
,
LuaValue.optlong(long)
,
LuaValue.optint(int)
,
LuaValue.checkint()
,
LuaValue.toint()
,
LuaValue.tonumber()
,
LuaValue.isnumber()
,
LuaValue.TNUMBER
public LuaValue tonumber()
LuaValue
In lua all numbers are strings, but not all strings are numbers.
This function will return
the LuaValue
this
if it is a number
or a string convertible to a number,
and LuaValue.NIL
for all other cases.
This allows values to be tested for their "numeric-ness" without the penalty of throwing exceptions, nor the cost of converting the type and creating storage for it.
tonumber
in class LuaValue
this
if it is a LuaNumber
or LuaString
that can be converted to a number,
otherwise LuaValue.NIL
LuaValue.tostring()
,
LuaValue.optnumber(LuaNumber)
,
LuaValue.checknumber()
,
LuaValue.toint()
,
LuaValue.todouble()
public boolean isnumber()
LuaValue
this
is a number
isnumber
in class LuaValue
number
,
meaning derives from LuaNumber
or derives from LuaString
and is convertible to a number,
otherwise falseLuaValue.tonumber()
,
LuaValue.checknumber()
,
LuaValue.optnumber(LuaNumber)
,
LuaValue.TNUMBER
public boolean isstring()
LuaValue
this
is a string
isstring
in class LuaValue
string
,
meaning derives from LuaString
or LuaNumber
,
otherwise falseLuaValue.tostring()
,
LuaValue.checkstring()
,
LuaValue.optstring(LuaString)
,
LuaValue.TSTRING
public LuaValue getmetatable()
LuaValue
LuaValue
For LuaTable
and LuaUserdata
instances,
the metatable returned is this instance metatable.
For all other types, the class metatable value will be returned.
getmetatable
in class LuaValue
LuaBoolean.s_metatable
,
s_metatable
,
LuaNil.s_metatable
,
LuaFunction.s_metatable
,
LuaThread.s_metatable
public LuaValue concat(LuaValue rhs)
LuaValue
Only strings and numbers as represented can be concatenated, meaning
each operand must derive from LuaString
or LuaNumber
.
concat
in class LuaValue
rhs
- The right-hand-side value to perform the operation with
LuaValue
resulting from concatenation of (this .. rhs)
public Buffer concat(Buffer rhs)
LuaValue
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
.
concat
in class LuaValue
rhs
- The right-hand-side Buffer
to perform the operation with
(this .. rhs)
public LuaValue concatTo(LuaNumber lhs)
LuaValue
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
.
concatTo
in class LuaValue
lhs
- The left-hand-side value onto which this will be concatenated
LuaValue
resulting from concatenation of (lhs .. this)
LuaValue.concat(LuaValue)
public LuaValue concatTo(LuaString lhs)
LuaValue
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
.
concatTo
in class LuaValue
lhs
- The left-hand-side value onto which this will be concatenated
LuaValue
resulting from concatenation of (lhs .. this)
LuaValue.concat(LuaValue)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |