|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
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.
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, 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:
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
,
Globals.compiler
Field Summary | |
---|---|
Prototype |
p
|
UpValue[] |
upValues
|
Fields inherited from class org.luaj.vm2.LuaFunction |
---|
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 |
Constructor Summary | |
---|---|
LuaClosure(Prototype p,
LuaValue env)
Create a closure around a Prototype with a specific 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 |
java.lang.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 |
protected void |
setUpvalue(int i,
LuaValue v)
|
java.lang.String |
tojstring()
Convert to human readable String for any type. |
Methods inherited from class org.luaj.vm2.LuaFunction |
---|
checkfunction, classnamestub, isfunction, optfunction, strvalue, 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, 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 UpValue[] upValues
Constructor Detail |
---|
public LuaClosure(Prototype p, LuaValue env)
p
- the Prototype to construct this Closure for.env
- the environment to associate with the closure.Method Detail |
---|
public boolean isclosure()
LuaValue
this
is a function
that is a closure,
meaning interprets lua bytecode for its execution
isclosure
in class LuaValue
closure
, otherwise falseLuaValue.isfunction()
,
LuaValue.checkclosure()
,
LuaValue.optclosure(LuaClosure)
,
LuaValue.TFUNCTION
public LuaClosure optclosure(LuaClosure defval)
LuaValue
LuaClosure
A LuaClosure
is a LuaFunction
that executes lua byteccode.
optclosure
in class LuaValue
defval
- 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.TFUNCTION
public LuaClosure checkclosure()
LuaValue
LuaClosure
,
or throw LuaError
if not
LuaClosure
is a subclass of LuaFunction
that interprets lua bytecode.
checkclosure
in class LuaValue
this
cast as LuaClosure
LuaValue.checkfunction()
,
LuaValue.optclosure(LuaClosure)
,
LuaValue.isclosure()
,
LuaValue.TFUNCTION
public LuaValue getmetatable()
LuaValue
LuaValue
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 LuaFunction
LuaBoolean.s_metatable
,
LuaNumber.s_metatable
,
LuaNil.s_metatable
,
LuaFunction.s_metatable
,
LuaThread.s_metatable
public java.lang.String tojstring()
LuaValue
tojstring
in class LuaFunction
LuaValue.tostring()
,
LuaValue.optjstring(String)
,
LuaValue.checkjstring()
,
LuaValue.isstring()
,
LuaValue.TSTRING
public final LuaValue call()
LuaValue
this
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
in class 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)
LuaValue
this
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
in class LuaValue
arg
- 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)
LuaValue
this
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
in class LuaValue
arg1
- 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)
LuaValue
this
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
in class LuaValue
arg1
- 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)
LuaValue
this
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
in class LuaValue
varargs
- 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 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
in class LuaValue
varargs
- 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)
public java.lang.String name()
LuaFunction
name
in class LuaFunction
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |