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

## org.luaj.vm2
Class LuaFunction

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

Direct Known Subclasses:
  LibFunction, LuaClosure

    public abstract class LuaFunction

extends LuaValue

Base class for functions implemented in Java.

Direct subclass include `LibFunction` which is the base class for all built-in library functions coded in Java, and `LuaClosure`, which represents a lua closure whose bytecode is interpreted when the function is invoked.

See Also:
  `LuaValue`, `LuaClosure`, `LibFunction`

Field Summary
`static LuaValue` `s_metatable` Shared static metatable for all functions and closures.

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

Method Summary
`LuaFunction` `checkfunction()` Check that the value is a function , or throw `LuaError` if not
`java.lang.String` `classnamestub()` Return the last part of the class name, to be used as a function name in tojstring and elsewhere.
`LuaValue` `getmetatable()` Get the metatable for this `LuaValue`
`boolean` `isfunction()` Check if `this` is a `function`
`java.lang.String` `name()` Return a human-readable name for this function.
`LuaFunction` `optfunction(LuaFunction defval)` Check that optional argument is a function and return as `LuaFunction`
`LuaString` `strvalue()` Convert this value to a string if it is a `LuaString` or `LuaNumber`, or throw a `LuaError` if it is not
`java.lang.String` `tojstring()` Convert to human readable String for any type.
`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, checkglobals, checkint, checkinteger, checkjstring, checklong, checkmetatag, checknotnil, checknumber, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, compareerror, compareerror, comparemt, concat, concat, concatmt, concatTo, concatTo, 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, isint, isinttype, islong, isnil, isnumber, isstring, 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, optint, optinteger, optjstring, optlong, optnumber, 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, sub, sub, sub, subargs, subFrom, subFrom, tableOf, tableOf, tableOf, tableOf, tableOf, tableOf, tailcallOf, testfor_b, toboolean, tobyte, tochar, todouble, tofloat, toint, tolong, tonumber, 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 functions and closures.

Constructor Detail

### LuaFunction

    public LuaFunction()

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

### isfunction

    public boolean isfunction()

  Description copied from class: `LuaValue`
  Check if `this` is a `function`

  Overrides:
    `isfunction` in class `LuaValue`
  Returns:
    true if this is a `function`, otherwise false
  See Also:
    `LuaValue.isclosure()`, `LuaValue.checkfunction()`, `LuaValue.optfunction(LuaFunction)`, `LuaValue.TFUNCTION`

### checkfunction

    public LuaFunction checkfunction()

  Description copied from class: `LuaValue`
  Check that the value is a function , or throw `LuaError` if not

  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:
    `checkfunction` in class `LuaValue`
  Returns:
    `this` if it is a lua function or closure
  See Also:
    `LuaValue.checkclosure()`

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

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

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

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

### classnamestub

    public java.lang.String classnamestub()

  Return the last part of the class name, to be used as a function name in tojstring and elsewhere.

  Returns:
    String naming the last part of the class name after the last dot (.) or dollar sign ($).

### name

    public java.lang.String name()

  Return a human-readable name for this function. Returns the last part of the class name by default. Is overridden by LuaClosure to return the source file and line, and by LibFunctions to return the name.

  Returns:
    common name for this function.

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