# LuaNumber (Luaj API)
Date: 2015-04-29

## org.luaj.vm2
Class LuaNumber

    java.lang.Object
      org.luaj.vm2.Varargs
          org.luaj.vm2.LuaValue
              org.luaj.vm2.LuaNumber

Direct Known Subclasses:
  LuaDouble, LuaInteger

    public abstract class LuaNumber

extends LuaValue

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.

See Also:
  `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.LuaValue

`add, add, add, and, arg, arg1, argerror, argerror, aritherror, aritherror, arithmt, arithmtwith, assert_, buffer, call, call, call, call, call, callmt, checkboolean, checkclosure, checkdouble, checkfunction, checkglobals, checkint, checkinteger, checkjstring, checklong, checkmetatag, checknotnil, checkstring, checktable, checkthread, checkuserdata, checkuserdata, compareerror, compareerror, comparemt, concatmt, concatTo, div, div, div, divInto, eq_b, eq, eqmtcall, equals, error, get, get, get, gettable, gt_b, gt_b, gt_b, gt, gt, gt, gteq_b, gteq_b, gteq_b, gteq, gteq, gteq, illegal, inext, initupvalue1, invoke, invoke, invoke, invoke, invoke, invoke, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, isboolean, isclosure, isfunction, isint, isinttype, islong, isnil, istable, isthread, isuserdata, isuserdata, isvalidkey, len, lenerror, length, listOf, listOf, load, lt_b, lt_b, lt_b, lt, lt, lt, lteq_b, lteq_b, lteq_b, lteq, lteq, lteq, metatableOf, metatag, method, method, method, method, method, method, mod, mod, mod, modFrom, mul, mul, mul, narg, neg, neq_b, neq, next, not, onInvoke, optboolean, optclosure, optdouble, optfunction, optint, optinteger, optjstring, optlong, optstring, opttable, optthread, optuserdata, optuserdata, optvalue, or, pow, pow, pow, powWith, powWith, presize, raweq, raweq, raweq, raweq, raweq, rawget, rawget, rawget, rawlen, rawset, rawset, rawset, rawset, rawset, rawset, rawset, rawsetlist, set, set, set, set, set, set, set, setmetatable, settable, strcmp, strcmp, strongvalue, strvalue, sub, sub, sub, subargs, subFrom, subFrom, tableOf, tableOf, tableOf, tableOf, tableOf, tableOf, tailcallOf, testfor_b, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, tolong, toshort, tostring, toString, touserdata, touserdata, typerror, unimplemented, userdataOf, userdataOf, valueOf, valueOf, valueOf, 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, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### s_metatable

    public static LuaValue s_metatable

  Shared static metatable for all number values represented in lua.

Constructor Detail

### LuaNumber

    public LuaNumber()

Method Detail

### 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()`

### 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 errmsg)

  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:
    `errmsg` - 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`

### 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`

### tonumber

    public LuaValue tonumber()

  Description copied from class: `LuaValue`
  Conditionally convert to lua number without throwing errors.

  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.

  Overrides:
    `tonumber` in class `LuaValue`
  Returns:
    `this` if it is a `LuaNumber` or `LuaString` that can be converted to a number, otherwise `LuaValue.NIL`
  See Also:
    `LuaValue.tostring()`, `LuaValue.optnumber(LuaNumber)`, `LuaValue.checknumber()`, `LuaValue.toint()`, `LuaValue.todouble()`

### 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`

### 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`, `s_metatable`, `LuaNil.s_metatable`, `LuaFunction.s_metatable`, `LuaThread.s_metatable`

### 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)`

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