public class LuaClosure extends LuaFunction
LuaFunction which executes lua bytecode.
A LuaClosure is a combination of a Prototype
and a LuaValue to use as an environment for execution.
Normally the LuaValue is a Globals in which case the environment
will contain standard lua libraries.
There are three main ways LuaClosure instances are created:
LuaClosure(Prototype, Globals, LuaValue)Globals.load(java.io.Reader, String)
Lua.OP_CLOSURE as part of bytecode processing
To construct it directly, the Prototype is typically created via a compiler such as
LuaC:
String script = "print( 'hello, world' )";
InputStream is = new ByteArrayInputStream(script.getBytes());
Prototype p = LuaC.instance.compile(is, "script");
LuaValue globals = JsePlatform.standardGlobals();
LuaClosure f = new LuaClosure(p, globals);
f.call();
To construct it indirectly, the Globals.load(java.io.Reader, String) method may be used:
Globals globals = JsePlatform.standardGlobals();
LuaFunction f = globals.load(new StringReader(script), "script");
LuaClosure c = f.checkclosure(); // This may fail if LuaJC is installed.
c.call();
In this example, the "checkclosure()" may fail if direct lua-to-java-bytecode
compiling using LuaJC is installed, because no LuaClosure is created in that case
and the value returned is a LuaFunction but not a LuaClosure.
Since a LuaClosure is a LuaFunction which is a LuaValue,
all the value operations can be used directly such as:
| 限定符和类型 | 字段和说明 |
|---|---|
Prototype |
p |
UpValue[] |
upValues |
s_metatableADD, BAND, BNOT, BOR, BXOR, CALL, CONCAT, DIV, EMPTYSTRING, ENV, EQ, FALSE, IDIV, INDEX, LE, LEN, LT, METATABLE, MINUSONE, MOD, MODE, MUL, NEWINDEX, NIL, NILS, NONE, NOVALS, ONE, POW, SHL, SHR, SUB, TBOOLEAN, TFUNCTION, TINT, TLIGHTUSERDATA, TNIL, TNONE, TNUMBER, TOSTRING, TRUE, TSTRING, TTABLE, TTHREAD, TUSERDATA, TVALUE, TYPE_NAMES, UNM, uservalue, ZERO| 构造器和说明 |
|---|
LuaClosure(Prototype p,
Globals globals,
LuaValue env)
Create a closure around a Prototype with a specific environment.
|
| 限定符和类型 | 方法和说明 |
|---|---|
LuaValue |
call()
Call
this with 0 arguments, including metatag processing,
and return only the first return value. |
LuaValue |
call(LuaValue arg)
Call
this with 1 argument, including metatag processing,
and return only the first return value. |
LuaValue |
call(LuaValue arg1,
LuaValue arg2)
Call
this with 2 arguments, including metatag processing,
and return only the first return value. |
LuaValue |
call(LuaValue arg1,
LuaValue arg2,
LuaValue arg3)
Call
this with 3 arguments, including metatag processing,
and return only the first return value. |
LuaClosure |
checkclosure()
Check that the value is a
LuaClosure ,
or throw LuaError if not
LuaClosure is a subclass of LuaFunction that interprets lua bytecode. |
protected Varargs |
execute(LuaValue[] stack,
Varargs varargs) |
LuaValue |
getmetatable()
Get the metatable for this
LuaValue
For LuaTable and LuaUserdata instances,
the metatable returned is this instance metatable. |
protected LuaValue |
getUpvalue(int i) |
Varargs |
invoke(Varargs varargs)
Call
this with variable arguments, including metatag processing,
and retain all return values in a Varargs. |
boolean |
isclosure()
Check if
this is a function that is a closure,
meaning interprets lua bytecode for its execution |
String |
name()
Return a human-readable name for this function.
|
Varargs |
onInvoke(Varargs varargs)
Callback used during tail call processing to invoke the function once.
|
LuaClosure |
optclosure(LuaClosure defval)
Check that optional argument is a closure and return as
LuaClosure
A LuaClosure is a LuaFunction that executes lua byteccode. |
protected void |
setUpvalue(int i,
LuaValue v) |
String |
tojstring()
Convert to human readable String for any type.
|
checkfunction, classnamestub, getfenv, isfunction, optfunction, setfenv, strvalue, type, typenameadd, add, add, and, arg, arg1, argerror, argerror, aritherror, aritherror, arithmt, arithmtwith, assert_, band, band, bnot, bor, bor, buffer, bxor, bxor, call, callmt, checkboolean, 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, getuservalue, gt_b, gt_b, gt_b, gt, gt, gt, gteq_b, gteq_b, gteq_b, gteq, gteq, gteq, idiv, idiv, illegal, inext, initupvalue1, invoke, invoke, invoke, invoke, invoke, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, invokemethod, isboolean, isint, isinttype, islong, isnil, isnumber, isstring, istable, isthread, isuserdata, isuserdata, isvalidkey, jcall, jget, jset, 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, optboolean, 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, setuservalue, shl, shl, shr, shr, 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, valueOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOf, varargsOfargcheck, checkboolean, checkclosure, checkdouble, checkfunction, checkint, checkinteger, checkjstring, checklong, checknotnil, checknumber, checkstring, checktable, checkthread, checkuserdata, checkuserdata, checkvalue, dealias, 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, typepublic LuaClosure(Prototype p, Globals globals, LuaValue env)
p - the Prototype to construct this Closure for.env - the environment to associate with the closure.public boolean isclosure()
LuaValuethis is a function that is a closure,
meaning interprets lua bytecode for its executionisclosure 在类中 LuaValueclosure, otherwise falseLuaValue.isfunction(),
LuaValue.checkclosure(),
LuaValue.optclosure(LuaClosure),
LuaValue.TFUNCTIONpublic LuaClosure optclosure(LuaClosure defval)
LuaValueLuaClosure
A LuaClosure is a LuaFunction that executes lua byteccode.
optclosure 在类中 LuaValuedefval - LuaClosure to return if this is nil or nonethis cast to LuaClosure if a function,
defval if nil or none,
throws LuaError otherwiseLuaValue.checkclosure(),
LuaValue.isclosure(),
LuaValue.TFUNCTIONpublic LuaClosure checkclosure()
LuaValueLuaClosure ,
or throw LuaError if not
LuaClosure is a subclass of LuaFunction that interprets lua bytecode.
checkclosure 在类中 LuaValuethis cast as LuaClosureLuaValue.checkfunction(),
LuaValue.optclosure(LuaClosure),
LuaValue.isclosure(),
LuaValue.TFUNCTIONpublic LuaValue getmetatable()
LuaValueLuaValue
For LuaTable and LuaUserdata instances,
the metatable returned is this instance metatable.
For all other types, the class metatable value will be returned.
getmetatable 在类中 LuaFunctionLuaBoolean.s_metatable,
LuaNumber.s_metatable,
LuaNil.s_metatable,
LuaFunction.s_metatable,
LuaThread.s_metatablepublic String tojstring()
LuaValuetojstring 在类中 LuaFunctionLuaValue.tostring(),
LuaValue.optjstring(String),
LuaValue.checkjstring(),
LuaValue.isstring(),
LuaValue.TSTRINGpublic final LuaValue call()
LuaValuethis with 0 arguments, including metatag processing,
and return only the first return value.
If this is a LuaFunction, call it,
and return only its first return value, dropping any others.
Otherwise, look for the LuaValue.CALL metatag and call that.
If the return value is a Varargs, only the 1st value will be returned.
To get multiple values, use LuaValue.invoke() instead.
To call this as a method call, use LuaValue.method(LuaValue) instead.
call 在类中 LuaValue(this()), or LuaValue.NIL if there were none.LuaValue.call(LuaValue),
LuaValue.call(LuaValue,LuaValue),
LuaValue.call(LuaValue, LuaValue, LuaValue),
LuaValue.invoke(),
LuaValue.method(String),
LuaValue.method(LuaValue)public final LuaValue call(LuaValue arg)
LuaValuethis with 1 argument, including metatag processing,
and return only the first return value.
If this is a LuaFunction, call it,
and return only its first return value, dropping any others.
Otherwise, look for the LuaValue.CALL metatag and call that.
If the return value is a Varargs, only the 1st value will be returned.
To get multiple values, use LuaValue.invoke() instead.
To call this as a method call, use LuaValue.method(LuaValue) instead.
call 在类中 LuaValuearg - First argument to supply to the called function(this(arg)), or LuaValue.NIL if there were none.LuaValue.call(),
LuaValue.call(LuaValue,LuaValue),
LuaValue.call(LuaValue, LuaValue, LuaValue),
LuaValue.invoke(Varargs),
LuaValue.method(String,LuaValue),
LuaValue.method(LuaValue,LuaValue)public final LuaValue call(LuaValue arg1, LuaValue arg2)
LuaValuethis with 2 arguments, including metatag processing,
and return only the first return value.
If this is a LuaFunction, call it,
and return only its first return value, dropping any others.
Otherwise, look for the LuaValue.CALL metatag and call that.
If the return value is a Varargs, only the 1st value will be returned.
To get multiple values, use LuaValue.invoke() instead.
To call this as a method call, use LuaValue.method(LuaValue) instead.
call 在类中 LuaValuearg1 - First argument to supply to the called functionarg2 - Second argument to supply to the called function(this(arg1,arg2)), or LuaValue.NIL if there were none.LuaValue.call(),
LuaValue.call(LuaValue),
LuaValue.call(LuaValue, LuaValue, LuaValue),
LuaValue.invoke(LuaValue, Varargs),
LuaValue.method(String,LuaValue,LuaValue),
LuaValue.method(LuaValue,LuaValue,LuaValue)public final LuaValue call(LuaValue arg1, LuaValue arg2, LuaValue arg3)
LuaValuethis with 3 arguments, including metatag processing,
and return only the first return value.
If this is a LuaFunction, call it,
and return only its first return value, dropping any others.
Otherwise, look for the LuaValue.CALL metatag and call that.
If the return value is a Varargs, only the 1st value will be returned.
To get multiple values, use LuaValue.invoke() instead.
To call this as a method call, use LuaValue.method(LuaValue) instead.
call 在类中 LuaValuearg1 - First argument to supply to the called functionarg2 - Second argument to supply to the called functionarg3 - Second argument to supply to the called function(this(arg1,arg2,arg3)), or LuaValue.NIL if there were none.LuaValue.call(),
LuaValue.call(LuaValue),
LuaValue.call(LuaValue, LuaValue),
LuaValue.invoke(LuaValue, LuaValue, Varargs),
LuaValue.invokemethod(String,Varargs),
LuaValue.invokemethod(LuaValue,Varargs)public final Varargs invoke(Varargs varargs)
LuaValuethis with variable arguments, including metatag processing,
and retain all return values in a Varargs.
If this is a LuaFunction, call it, and return all values.
Otherwise, look for the LuaValue.CALL metatag and call that.
To get a particular return value, us Varargs.arg(int)
To call this as a method call, use LuaValue.invokemethod(LuaValue) instead.
invoke 在类中 LuaValuevarargs - Varargs containing the arguments to supply to the called functionVarargs instance.LuaValue.varargsOf(LuaValue[]),
LuaValue.call(LuaValue),
LuaValue.invoke(),
LuaValue.invoke(LuaValue,Varargs),
LuaValue.invokemethod(String,Varargs),
LuaValue.invokemethod(LuaValue,Varargs)public final Varargs onInvoke(Varargs varargs)
LuaValue
This may return a TailcallVarargs to be evaluated by the client.
This should not be called directly, instead use one of the call invocation functions.
onInvoke 在类中 LuaValuevarargs - the arguments to the call invocation.LuaValue.call(),
LuaValue.invoke(),
LuaValue.method(LuaValue),
LuaValue.invokemethod(LuaValue)protected LuaValue getUpvalue(int i)
protected void setUpvalue(int i,
LuaValue v)
public String name()
LuaFunctionname 在类中 LuaFunctionCopyright © 2020. All rights reserved.