|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.luaj.vm2.Varargs
org.luaj.vm2.LuaValue
org.luaj.vm2.LuaFunction
org.luaj.vm2.LuaClosure
public class LuaClosure
Extension of LuaFunction which executes lua bytecode.
A LuaClosure is a combination of a Prototype
and a LuaValue to use as an environment for execution.
There are three main ways LuaClosure instances are created:
LuaClosure(Prototype, LuaValue)LoadState.LuaCompiler.load(java.io.InputStream, String, LuaValue)
Lua.OP_CLOSURE as part of bytecode processing
To construct it directly, the Prototype is typically created via a compiler such as LuaC:
InputStream is = new ByteArrayInputStream("print('hello,world').getBytes());
Prototype p = LuaC.instance.compile(is, "script");
LuaValue _G = JsePlatform.standardGlobals()
LuaClosure f = new LuaClosure(p, _G);
To construct it indirectly, the LuaC compiler may be used,
which implements the LoadState.LuaCompiler interface:
LuaFunction f = LuaC.instance.load(is, "script", _G);
Typically, a closure that has just been loaded needs to be initialized by executing it, and its return value can be saved if needed:
LuaValue r = f.call();
_G.set( "mypkg", r )
In the preceding, the loaded value is typed as LuaFunction
to allow for the possibility of other compilers such as LuaJC
producing LuaFunction directly without
creating a Prototype or LuaClosure.
Since a LuaClosure is a LuaFunction which is a LuaValue,
all the value operations can be used directly such as:
LuaValue.setfenv(LuaValue)LuaValue.call()LuaValue.call(LuaValue)LuaValue.invoke()LuaValue.invoke(Varargs)LuaValue.method(String)LuaValue.method(String,LuaValue)LuaValue.invokemethod(String)LuaValue.invokemethod(String,Varargs)
LuaValue,
LuaFunction,
LuaValue.isclosure(),
LuaValue.checkclosure(),
LuaValue.optclosure(LuaClosure),
LoadState,
LoadState.compiler| Field Summary | |
|---|---|
Prototype |
p
|
UpValue[] |
upValues
|
| Fields inherited from class org.luaj.vm2.LuaFunction |
|---|
env, s_metatable |
| 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 | |
|---|---|
protected |
LuaClosure(int nupvalues,
LuaValue env)
|
|
LuaClosure(Prototype p,
LuaValue env)
Supply the initial environment |
| Method Summary | |
|---|---|
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 |
protected Varargs |
execute(LuaValue[] stack,
Varargs varargs)
|
LuaValue |
getmetatable()
Get the metatable for this LuaValue |
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 |
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 |
protected void |
setUpvalue(int i,
LuaValue v)
|
| Methods inherited from class org.luaj.vm2.LuaFunction |
|---|
checkfunction, getfenv, isfunction, optfunction, setfenv, type, typename |
| 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 |
|---|
public final Prototype p
public final UpValue[] upValues
| Constructor Detail |
|---|
public LuaClosure(Prototype p,
LuaValue env)
protected LuaClosure(int nupvalues,
LuaValue env)
| Method Detail |
|---|
public boolean isclosure()
LuaValuethis is a function that is a closure,
meaning interprets lua bytecode for its execution
isclosure in class LuaValueclosure, otherwise falseLuaValue.isfunction(),
LuaValue.checkclosure(),
LuaValue.optclosure(LuaClosure),
LuaValue.TFUNCTIONpublic LuaClosure optclosure(LuaClosure defval)
LuaValueLuaClosure
A LuaClosure is a that executes lua byteccode.
optclosure in class LuaValuedefval - LuaClosure to return if this is nil or none
this 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 that interprets lua bytecode.
checkclosure in class 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 in class LuaFunctionLuaBoolean.s_metatable,
LuaNumber.s_metatable,
LuaNil.s_metatable,
LuaFunction.s_metatable,
LuaThread.s_metatablepublic 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 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 in class LuaValue(this()), or 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 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 in class LuaValuearg - First argument to supply to the called function
(this(arg)), or NIL if there were none.LuaValue.call(),
LuaValue.call(LuaValue,LuaValue),
LuaValue.call(LuaValue, LuaValue, LuaValue),
#invoke(LuaValue),
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 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 in class LuaValuearg1 - First argument to supply to the called functionarg2 - Second argument to supply to the called function
(this(arg1,arg2)), or NIL if there were none.LuaValue.call(),
LuaValue.call(LuaValue),
LuaValue.call(LuaValue, LuaValue, LuaValue),
#invoke(LuaValue,LuaValue),
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 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 in class 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 NIL if there were none.LuaValue.call(),
LuaValue.call(LuaValue),
LuaValue.call(LuaValue, LuaValue),
#invoke(LuaValue,LuaValue, LuaValue),
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 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 in class LuaValuevarargs - Varargs containing the arguments to supply to the called function
Varargs instance.LuaValue.varargsOf(LuaValue[]),
LuaValue.call(LuaValue),
LuaValue.invoke(),
LuaValue.invoke(LuaValue,Varargs),
LuaValue.invokemethod(String,Varargs),
LuaValue.invokemethod(LuaValue,Varargs)public Varargs onInvoke(Varargs varargs)
LuaValue
This may return a TailcallVarargs to be evaluated by the client.
This should not be called directly, instead use on of the call invocation functions.
onInvoke in class LuaValuevarargs - the arguments to the call invocation.
LuaValue.call(),
LuaValue.invoke(),
LuaValue.method(LuaValue),
LuaValue.invokemethod(LuaValue)
protected Varargs execute(LuaValue[] stack,
Varargs varargs)
protected LuaValue getUpvalue(int i)
protected void setUpvalue(int i,
LuaValue v)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||