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

## org.luaj.vm2
Class LuaNil

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

    public class LuaNil

extends LuaValue

Class to encapsulate behavior of the singleton instance `nil`

There will be one instance of this class, `LuaValue.NIL`, per Java virtual machine. However, the `Varargs` instance `LuaValue.NONE` which is the empty list, is also considered treated as a nil value by default.

Although it is possible to test for nil using Java == operator, the recommended approach is to use the method `LuaValue.isnil()` instead. By using that any ambiguities between `LuaValue.NIL` and `LuaValue.NONE` are avoided.

See Also:
  `LuaValue`, `LuaValue.NIL`

Field Summary
`static LuaValue` `s_metatable`

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` `checknotnil()` Check that this is not the value `LuaValue.NIL`, or throw `LuaError` if it is
`boolean` `equals(java.lang.Object o)`
`LuaValue` `getmetatable()` Get the metatable for this `LuaValue`
`boolean` `isnil()` Check if `this` is `#NIL`
`boolean` `isvalidkey()` Return true if this is a valid key in a table index operation.
`LuaValue` `not()` Unary not: return inverse boolean value `(~this)` as defined by lua not operator
`boolean` `optboolean(boolean defval)` Check that optional argument is a boolean and return its boolean value
`LuaClosure` `optclosure(LuaClosure defval)` Check that optional argument is a closure and return as `LuaClosure`
`double` `optdouble(double defval)` Check that optional argument is a number or string convertible to number and return as double
`LuaFunction` `optfunction(LuaFunction defval)` Check that optional argument is a function and return as `LuaFunction`
`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`
`LuaTable` `opttable(LuaTable defval)` Check that optional argument is a table and return as `LuaTable`
`LuaThread` `optthread(LuaThread defval)` Check that optional argument is a thread and return as `LuaThread`
`java.lang.Object` `optuserdata(java.lang.Class c, java.lang.Object defval)` Check that optional argument is a userdata whose instance is of a type and return the Object instance
`java.lang.Object` `optuserdata(java.lang.Object defval)` Check that optional argument is a userdata and return the Object instance
`LuaValue` `optvalue(LuaValue defval)` Perform argument check that this is not nil or none.
`boolean` `toboolean()` Convert to boolean false if `LuaValue.NIL` or `LuaValue.FALSE`, true if anything else
`java.lang.String` `tojstring()` Convert to human readable String for any type.
`java.lang.String` `toString()` Convert the value to a human readable string using `LuaValue.tojstring()`
`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, checknumber, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, compareerror, compareerror, comparemt, concat, concat, concatmt, concatTo, concatTo, concatTo, div, div, div, divInto, eq_b, eq, eqmtcall, 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, isnumber, isstring, istable, isthread, isuserdata, isuserdata, 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, onInvoke, 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, tobyte, tochar, todouble, tofloat, toint, tolong, tonumber, toshort, 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

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

### toString

    public java.lang.String toString()

  Description copied from class: `LuaValue`
  Convert the value to a human readable string using `LuaValue.tojstring()`

  Overrides:
    `toString` in class `LuaValue`
  Returns:
    String value intended to be human readible.
  See Also:
    `LuaValue.tostring()`, `LuaValue.tojstring()`, `LuaValue.optstring(LuaString)`, `LuaValue.checkstring()`, `LuaValue.toString()`

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

### not

    public LuaValue not()

  Description copied from class: `LuaValue`
  Unary not: return inverse boolean value `(~this)` as defined by lua not operator

  Overrides:
    `not` in class `LuaValue`
  Returns:
    `LuaValue.TRUE` if `LuaValue.NIL` or `LuaValue.FALSE`, otherwise `LuaValue.FALSE`

### toboolean

    public boolean toboolean()

  Description copied from class: `LuaValue`
  Convert to boolean false if `LuaValue.NIL` or `LuaValue.FALSE`, true if anything else

  Overrides:
    `toboolean` in class `LuaValue`
  Returns:
    Value cast to byte if number or string convertible to number, otherwise 0
  See Also:
    `LuaValue.optboolean(boolean)`, `LuaValue.checkboolean()`, `LuaValue.isboolean()`, `LuaValue.TBOOLEAN`

### isnil

    public boolean isnil()

  Description copied from class: `LuaValue`
  Check if `this` is `#NIL`

  Overrides:
    `isnil` in class `LuaValue`
  Returns:
    true if this is `#NIL`, otherwise false
  See Also:
    `LuaValue.NIL`, `LuaValue.NONE`, `LuaValue.checknotnil()`, `LuaValue.optvalue(LuaValue)`, `Varargs.isnoneornil(int)`, `LuaValue.TNIL`, `LuaValue.TNONE`

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

### equals

    public boolean equals(java.lang.Object o)

  Overrides:
    `equals` in class `LuaValue`

### checknotnil

    public LuaValue checknotnil()

  Description copied from class: `LuaValue`
  Check that this is not the value `LuaValue.NIL`, or throw `LuaError` if it is

  Overrides:
    `checknotnil` in class `LuaValue`
  Returns:
    `this` if it is not `LuaValue.NIL`
  See Also:
    `LuaValue.optvalue(LuaValue)`

### isvalidkey

    public boolean isvalidkey()

  Description copied from class: `LuaValue`
  Return true if this is a valid key in a table index operation.

  Overrides:
    `isvalidkey` in class `LuaValue`
  Returns:
    true if valid as a table key, otherwise false
  See Also:
    `LuaValue.isnil()`, `LuaValue.isinttype()`

### optboolean

    public boolean optboolean(boolean defval)

  Description copied from class: `LuaValue`
  Check that optional argument is a boolean and return its boolean value

  Overrides:
    `optboolean` in class `LuaValue`
  Parameters:
    `defval` - boolean value to return if `this` is nil or none
  Returns:
    `this` cast to boolean if a `LuaBoolean`, `defval` if nil or none, throws `LuaError` otherwise
  See Also:
    `LuaValue.checkboolean()`, `LuaValue.isboolean()`, `LuaValue.TBOOLEAN`

### optclosure

    public LuaClosure optclosure(LuaClosure defval)

  Description copied from class: `LuaValue`
  Check that optional argument is a closure and return as `LuaClosure`

  A `LuaClosure` is a `LuaFunction` that executes lua byteccode.

  Overrides:
    `optclosure` in class `LuaValue`
  Parameters:
    `defval` - `LuaClosure` to return if `this` is nil or none
  Returns:
    `this` cast to `LuaClosure` if a function, `defval` if nil or none, throws `LuaError` otherwise
  See Also:
    `LuaValue.checkclosure()`, `LuaValue.isclosure()`, `LuaValue.TFUNCTION`

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

### optfunction

    public LuaFunction optfunction(LuaFunction defval)

  Description copied from class: `LuaValue`
  Check that optional argument is a function and return as `LuaFunction`

  A `LuaFunction` may either be a Java function that implements functionality directly in Java, or a `LuaClosure` which is a `LuaFunction` that executes lua bytecode.

  Overrides:
    `optfunction` in class `LuaValue`
  Parameters:
    `defval` - `LuaFunction` to return if `this` is nil or none
  Returns:
    `this` cast to `LuaFunction` if a function, `defval` if nil or none, throws `LuaError` otherwise
  See Also:
    `LuaValue.checkfunction()`, `LuaValue.isfunction()`, `LuaValue.TFUNCTION`

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

### opttable

    public LuaTable opttable(LuaTable defval)

  Description copied from class: `LuaValue`
  Check that optional argument is a table and return as `LuaTable`

  Overrides:
    `opttable` in class `LuaValue`
  Parameters:
    `defval` - `LuaTable` to return if `this` is nil or none
  Returns:
    `this` cast to `LuaTable` if a table, `defval` if nil or none, throws `LuaError` if some other type
  See Also:
    `LuaValue.checktable()`, `LuaValue.istable()`, `LuaValue.TTABLE`

### optthread

    public LuaThread optthread(LuaThread defval)

  Description copied from class: `LuaValue`
  Check that optional argument is a thread and return as `LuaThread`

  Overrides:
    `optthread` in class `LuaValue`
  Parameters:
    `defval` - `LuaThread` to return if `this` is nil or none
  Returns:
    `this` cast to `LuaTable` if a thread, `defval` if nil or none, throws `LuaError` if some other type
  See Also:
    `LuaValue.checkthread()`, `LuaValue.isthread()`, `LuaValue.TTHREAD`

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

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

### optuserdata

    public java.lang.Object optuserdata(java.lang.Object defval)

  Description copied from class: `LuaValue`
  Check that optional argument is a userdata and return the Object instance

  Overrides:
    `optuserdata` in class `LuaValue`
  Parameters:
    `defval` - Object to return if `this` is nil or none
  Returns:
    Object instance of the userdata if a `LuaUserdata`, `defval` if nil or none, throws `LuaError` if some other type
  See Also:
    `LuaValue.checkuserdata()`, `LuaValue.isuserdata()`, `LuaValue.optuserdata(Class, Object)`, `LuaValue.TUSERDATA`

### optuserdata

    public java.lang.Object optuserdata(java.lang.Class c,
                                        java.lang.Object defval)

  Description copied from class: `LuaValue`
  Check that optional argument is a userdata whose instance is of a type and return the Object instance

  Overrides:
    `optuserdata` in class `LuaValue`
  Parameters:
    `c` - Class to test userdata instance against
    `defval` - Object to return if `this` is nil or none
  Returns:
    Object instance of the userdata if a `LuaUserdata` and instance is assignable to `c`, `defval` if nil or none, throws `LuaError` if some other type
  See Also:
    `LuaValue.checkuserdata(Class)`, `LuaValue.isuserdata(Class)`, `LuaValue.optuserdata(Object)`, `LuaValue.TUSERDATA`

### optvalue

    public LuaValue optvalue(LuaValue defval)

  Description copied from class: `LuaValue`
  Perform argument check that this is not nil or none.

  Overrides:
    `optvalue` in class `LuaValue`
  Parameters:
    `defval` - `LuaValue` to return if `this` is nil or none
  Returns:
    `this` if not nil or none, else `defval`
  See Also:
    `LuaValue.NIL`, `LuaValue.NONE`, `LuaValue.isnil()`, `Varargs.isnoneornil(int)`, `LuaValue.TNIL`, `LuaValue.TNONE`

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