org.luaj.vm2
Class LuaFunction

java.lang.Object
  extended by org.luaj.vm2.Varargs
      extended by org.luaj.vm2.LuaValue
          extended by 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, LibFunction, LuaClosure

Field Summary
protected  LuaValue env
           
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, 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()
           
LuaFunction(LuaValue env)
           
 
Method Summary
 LuaValue checkfunction()
          Check that the value is a function , or throw LuaError if not
 LuaValue getfenv()
          Get the environemnt for an instance.
 LuaValue getmetatable()
          Get the metatable for this LuaValue
 boolean isfunction()
          Check if this is a function
 LuaFunction optfunction(LuaFunction defval)
          Check that optional argument is a function and return as LuaFunction
 void setfenv(LuaValue env)
          Set the environment on an object.
 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, callmt, checkboolean, checkclosure, checkdouble, checkint, checkinteger, checkjstring, checklong, checkmetatag, checknotnil, checknumber, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalidkey, compareerror, compareerror, comparemt, concat, concat, concatmt, concatTo, concatTo, concatTo, div, div, div, divInto, eq_b, eq, eqmtcall, equals, error, get, get, get, getn, gettable, gt_b, gt_b, gt_b, gt, gt, gt, gteq_b, gteq_b, gteq_b, gteq, gteq, gteq, illegal, inext, invoke, invoke, invoke, invoke, invoke, invoke, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, isboolean, isclosure, isint, isinttype, islong, isnil, isnumber, isstring, istable, isthread, isuserdata, isuserdata, isweaknil, len, lenerror, length, listOf, listOf, load, lt_b, lt_b, lt_b, lt, lt, lt, lteq_b, lteq_b, lteq_b, lteq, lteq, lteq, 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, rawset, rawset, rawset, rawset, rawset, rawset, rawset, rawsetlist, set, set, set, set, set, set, set, setmetatable, settable, strcmp, strcmp, strongkey, strongvalue, strvalue, sub, sub, sub, subFrom, subFrom, tableOf, tableOf, tableOf, tableOf, tableOf, tableOf, tailcallOf, testfor_b, toboolean, tobyte, tochar, todouble, tofloat, toint, tojstring, 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, subargs, 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.


env

protected LuaValue env
Constructor Detail

LuaFunction

public LuaFunction()

LuaFunction

public LuaFunction(LuaValue env)
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 TNIL, TBOOLEAN, TNUMBER, TSTRING, TTABLE, TFUNCTION, TUSERDATA, 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(), #optfunciton(LuaFunction), LuaValue.TFUNCTION

checkfunction

public LuaValue checkfunction()
Description copied from class: LuaValue
Check that the value is a function , or throw LuaError if not

A function is considered anything whose LuaValue.type() returns TFUNCTION. In practice it will be either a built-in Java function, typically deriving from LuaFunction or a LuaClosure which represents lua source compiled into lua bytecode.

Overrides:
checkfunction in class LuaValue
Returns:
this if if 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

getfenv

public LuaValue getfenv()
Description copied from class: LuaValue
Get the environemnt for an instance.

Overrides:
getfenv in class LuaValue
Returns:
LuaValue currently set as the instances environent.

setfenv

public void setfenv(LuaValue env)
Description copied from class: LuaValue
Set the environment on an object.

Typically the environment is created once per application via a platform helper method such as JsePlatform.standardGlobals() However, any object can serve as an environment if it contains suitable metatag values to implement LuaValue.get(LuaValue) to provide the environment values.

Overrides:
setfenv in class LuaValue
Parameters:
env - LuaValue (typically a LuaTable) containing the environment.
See Also:
JmePlatform, JsePlatform


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