|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.luaj.vm2.Varargs
public abstract class Varargs
Class to encapsulate varargs values, either as part of a variable argument list, or multiple return values.
To construct varargs, use one of the static methods such as
LuaValue.varargsOf(LuaValue,LuaValue)
Any LuaValue can be used as a stand-in for Varargs, for both calls and return values. When doing so, nargs() will return 1 and arg1() or arg(1) will return this. This simplifies the case when calling or implementing varargs functions with only 1 argument or 1 return value.
Varargs can also be derived from other varargs by appending to the front with a call
such as LuaValue.varargsOf(LuaValue,Varargs)
or by taking a portion of the args using Varargs.subargs(int start)
LuaValue.varargsOf(LuaValue[])
,
LuaValue.varargsOf(LuaValue, Varargs)
,
LuaValue.varargsOf(LuaValue[], Varargs)
,
LuaValue.varargsOf(LuaValue, LuaValue, Varargs)
,
LuaValue.varargsOf(LuaValue[], int, int)
,
LuaValue.varargsOf(LuaValue[], int, int, Varargs)
,
subargs(int)
Constructor Summary | |
---|---|
Varargs()
|
Method Summary | |
---|---|
abstract LuaValue |
arg(int i)
Get the n-th argument value (1-based). |
abstract LuaValue |
arg1()
Get the first argument in the list. |
void |
argcheck(boolean test,
int i,
java.lang.String msg)
Return argument i as a LuaValue when a user-supplied assertion passes, or throw an error. |
boolean |
checkboolean(int i)
Return argument i as a boolean value, or throw an error if any other type. |
LuaClosure |
checkclosure(int i)
Return argument i as a closure, or throw an error if any other type. |
double |
checkdouble(int i)
Return argument i as a double, or throw an error if it cannot be converted to one. |
LuaValue |
checkfunction(int i)
Return argument i as a function, or throw an error if an incompatible type. |
int |
checkint(int i)
Return argument i as a java int value, discarding any fractional part, or throw an error if not a number. |
LuaInteger |
checkinteger(int i)
Return argument i as a java int value, or throw an error if not a number or is not representable by a java int. |
java.lang.String |
checkjstring(int i)
Return argument i as a java String if a string or number, or throw an error if any other type |
long |
checklong(int i)
Return argument i as a java long value, discarding any fractional part, or throw an error if not a number. |
LuaValue |
checknotnil(int i)
Return argument i as a LuaValue if it is not nil, or throw an error if it is nil. |
LuaNumber |
checknumber(int i)
Return argument i as a LuaNumber, or throw an error if not a number or string that can be converted to a number. |
LuaString |
checkstring(int i)
Return argument i as a LuaString if a string or number, or throw an error if any other type |
LuaTable |
checktable(int i)
Return argument i as a LuaTable if a lua table, or throw an error if any other type. |
LuaThread |
checkthread(int i)
Return argument i as a LuaThread if a lua thread, or throw an error if any other type. |
java.lang.Object |
checkuserdata(int i)
Return argument i as a java Object if a userdata, or throw an error if any other type. |
java.lang.Object |
checkuserdata(int i,
java.lang.Class c)
Return argument i as a java Object if it is a userdata whose instance Class c or a subclass, or throw an error if any other type. |
LuaValue |
checkvalue(int i)
Return argument i as a LuaValue if it exists, or throw an error. |
Varargs |
eval()
Evaluate any pending tail call and return result. |
boolean |
isfunction(int i)
Tests if argument i is a function. |
boolean |
isnil(int i)
Tests if argument i is nil. |
boolean |
isnoneornil(int i)
Return true if there is no argument or nil at argument i. |
boolean |
isnumber(int i)
Tests if argument i is a number. |
boolean |
isstring(int i)
Tests if argument i is a string. |
boolean |
istable(int i)
Tests if argument i is a table. |
boolean |
isTailcall()
Return true if this is a TailcallVarargs |
boolean |
isthread(int i)
Tests if argument i is a thread. |
boolean |
isuserdata(int i)
Tests if argument i is a userdata. |
boolean |
isvalue(int i)
Tests if a value exists at argument i. |
abstract int |
narg()
Get the number of arguments, or 0 if there are none. |
boolean |
optboolean(int i,
boolean defval)
Return argument i as a boolean value, defval if nil, or throw a LuaError if any other type. |
LuaClosure |
optclosure(int i,
LuaClosure defval)
Return argument i as a closure, defval if nil, or throw a LuaError if any other type. |
double |
optdouble(int i,
double defval)
Return argument i as a double, defval if nil, or throw a LuaError if it cannot be converted to one. |
LuaFunction |
optfunction(int i,
LuaFunction defval)
Return argument i as a function, defval if nil, or throw a LuaError if an incompatible type. |
int |
optint(int i,
int defval)
Return argument i as a java int value, discarding any fractional part, defval if nil, or throw a LuaError if not a number. |
LuaInteger |
optinteger(int i,
LuaInteger defval)
Return argument i as a java int value, defval if nil, or throw a LuaError if not a number or is not representable by a java int. |
java.lang.String |
optjstring(int i,
java.lang.String defval)
Return argument i as a java String if a string or number, defval if nil, or throw a LuaError if any other type |
long |
optlong(int i,
long defval)
Return argument i as a java long value, discarding any fractional part, defval if nil, or throw a LuaError if not a number. |
LuaNumber |
optnumber(int i,
LuaNumber defval)
Return argument i as a LuaNumber, defval if nil, or throw a LuaError if not a number or string that can be converted to a number. |
LuaString |
optstring(int i,
LuaString defval)
Return argument i as a LuaString if a string or number, defval if nil, or throw a LuaError if any other type |
LuaTable |
opttable(int i,
LuaTable defval)
Return argument i as a LuaTable if a lua table, defval if nil, or throw a LuaError if any other type. |
LuaThread |
optthread(int i,
LuaThread defval)
Return argument i as a LuaThread if a lua thread, defval if nil, or throw a LuaError if any other type. |
java.lang.Object |
optuserdata(int i,
java.lang.Class c,
java.lang.Object defval)
Return argument i as a java Object if it is a userdata whose instance Class c or a subclass, defval if nil, or throw a LuaError if any other type. |
java.lang.Object |
optuserdata(int i,
java.lang.Object defval)
Return argument i as a java Object if a userdata, defval if nil, or throw a LuaError if any other type. |
LuaValue |
optvalue(int i,
LuaValue defval)
Return argument i as a LuaValue if it exists, or defval . |
Varargs |
subargs(int start)
Create a Varargs instance containing arguments starting at index start |
boolean |
toboolean(int i)
Convert argument i to java boolean based on lua rules for boolean evaluation. |
byte |
tobyte(int i)
Return argument i as a java byte value, discarding any fractional part and truncating, or 0 if not a number. |
char |
tochar(int i)
Return argument i as a java char value, discarding any fractional part and truncating, or 0 if not a number. |
double |
todouble(int i)
Return argument i as a java double value or 0 if not a number. |
float |
tofloat(int i)
Return argument i as a java float value, discarding excess fractional part and truncating, or 0 if not a number. |
int |
toint(int i)
Return argument i as a java int value, discarding any fractional part and truncating, or 0 if not a number. |
java.lang.String |
tojstring()
Convert the list of varargs values to a human readable java String. |
java.lang.String |
tojstring(int i)
Return argument i as a java String based on the type of the argument. |
long |
tolong(int i)
Return argument i as a java long value, discarding any fractional part and truncating, or 0 if not a number. |
short |
toshort(int i)
Return argument i as a java short value, discarding any fractional part and truncating, or 0 if not a number. |
java.lang.String |
toString()
Convert the value or values to a java String using Varargs.tojstring() |
java.lang.Object |
touserdata(int i)
Return argument i as a java Object if a userdata, or null. |
java.lang.Object |
touserdata(int i,
java.lang.Class c)
Return argument i as a java Object if it is a userdata whose instance Class c or a subclass, or null. |
int |
type(int i)
Gets the type of argument i |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Varargs()
Method Detail |
---|
public abstract LuaValue arg(int i)
i
- the index of the argument to get, 1 is the first argument
arg1()
,
LuaValue.NIL
public abstract int narg()
public abstract LuaValue arg1()
arg(int)
,
LuaValue.NIL
public Varargs eval()
public boolean isTailcall()
public int type(int i)
i
i
- the index of the argument to convert, 1 is the first argument
LuaValue.TNIL
,
LuaValue.TBOOLEAN
,
LuaValue.TNUMBER
,
LuaValue.TSTRING
,
LuaValue.TTABLE
,
LuaValue.TFUNCTION
,
LuaValue.TUSERDATA
,
LuaValue.TTHREAD
public boolean isnil(int i)
i
- the index of the argument to test, 1 is the first argument
LuaValue.TNIL
public boolean isfunction(int i)
i
- the index of the argument to test, 1 is the first argument
LuaValue.TFUNCTION
public boolean isnumber(int i)
i
- the index of the argument to test, 1 is the first argument
LuaValue.TNUMBER
,
LuaValue.TSTRING
public boolean isstring(int i)
i
- the index of the argument to test, 1 is the first argument
LuaValue.TNUMBER
,
LuaValue.TSTRING
public boolean istable(int i)
i
- the index of the argument to test, 1 is the first argument
LuaValue.TTABLE
public boolean isthread(int i)
i
- the index of the argument to test, 1 is the first argument
LuaValue.TTHREAD
public boolean isuserdata(int i)
i
- the index of the argument to test, 1 is the first argument
LuaValue.TUSERDATA
public boolean isvalue(int i)
i
- the index of the argument to test, 1 is the first argument
public boolean optboolean(int i, boolean defval)
defval
if nil, or throw a LuaError if any other type.
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a lua booleanpublic LuaClosure optclosure(int i, LuaClosure defval)
defval
if nil, or throw a LuaError if any other type.
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a lua closurepublic double optdouble(int i, double defval)
defval
if nil, or throw a LuaError if it cannot be converted to one.
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a numberpublic LuaFunction optfunction(int i, LuaFunction defval)
defval
if nil, or throw a LuaError if an incompatible type.
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a lua function or closurepublic int optint(int i, int defval)
defval
if nil, or throw a LuaError if not a number.
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a numberpublic LuaInteger optinteger(int i, LuaInteger defval)
defval
if nil, or throw a LuaError if not a number or is not representable by a java int.
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument cannot be represented by a java int valuepublic long optlong(int i, long defval)
defval
if nil, or throw a LuaError if not a number.
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a numberpublic LuaNumber optnumber(int i, LuaNumber defval)
defval
if nil, or throw a LuaError if not a number or string that can be converted to a number.
i
- the index of the argument to test, 1 is the first argument, or defval if not supplied or nil
LuaError
- if the argument is not a numberpublic java.lang.String optjstring(int i, java.lang.String defval)
defval
if nil, or throw a LuaError if any other type
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a string or numberpublic LuaString optstring(int i, LuaString defval)
defval
if nil, or throw a LuaError if any other type
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a string or numberpublic LuaTable opttable(int i, LuaTable defval)
defval
if nil, or throw a LuaError if any other type.
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a lua tablepublic LuaThread optthread(int i, LuaThread defval)
defval
if nil, or throw a LuaError if any other type.
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a lua threadpublic java.lang.Object optuserdata(int i, java.lang.Object defval)
defval
if nil, or throw a LuaError if any other type.
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a userdatapublic java.lang.Object optuserdata(int i, java.lang.Class c, java.lang.Object defval)
defval
if nil, or throw a LuaError if any other type.
i
- the index of the argument to test, 1 is the first argumentc
- the class to which the userdata instance must be assignable
LuaError
- if the argument is not a userdata or from whose instance c is not assignablepublic LuaValue optvalue(int i, LuaValue defval)
defval
.
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument does not exist.public boolean checkboolean(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a lua booleanpublic LuaClosure checkclosure(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a lua closurepublic double checkdouble(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a numberpublic LuaValue checkfunction(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a lua function or closurepublic int checkint(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a numberpublic LuaInteger checkinteger(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument cannot be represented by a java int valuepublic long checklong(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a numberpublic LuaNumber checknumber(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a numberpublic java.lang.String checkjstring(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a string or numberpublic LuaString checkstring(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a string or numberpublic LuaTable checktable(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a lua tablepublic LuaThread checkthread(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a lua threadpublic java.lang.Object checkuserdata(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument is not a userdatapublic java.lang.Object checkuserdata(int i, java.lang.Class c)
i
- the index of the argument to test, 1 is the first argumentc
- the class to which the userdata instance must be assignable
LuaError
- if the argument is not a userdata or from whose instance c is not assignablepublic LuaValue checkvalue(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument does not exist.public LuaValue checknotnil(int i)
i
- the index of the argument to test, 1 is the first argument
LuaError
- if the argument doesn't exist or evaluates to nil.public void argcheck(boolean test, int i, java.lang.String msg)
test
- user supplied assertion to test againsti
- the index to report in any error messagemsg
- the error message to use when the test fails
LuaError
- if the the value of test
is false
public boolean isnoneornil(int i)
i
- the index of the argument to test, 1 is the first argument
public boolean toboolean(int i)
i
to java boolean based on lua rules for boolean evaluation.
i
- the index of the argument to convert, 1 is the first argument
false
if argument i is nil or false, otherwise true
public byte tobyte(int i)
i
- the index of the argument to convert, 1 is the first argument
public char tochar(int i)
i
- the index of the argument to convert, 1 is the first argument
public double todouble(int i)
i
- the index of the argument to convert, 1 is the first argument
public float tofloat(int i)
i
- the index of the argument to convert, 1 is the first argument
public int toint(int i)
i
- the index of the argument to convert, 1 is the first argument
public long tolong(int i)
i
- the index of the argument to convert, 1 is the first argument
public java.lang.String tojstring(int i)
i
- the index of the argument to convert, 1 is the first argument
public short toshort(int i)
i
- the index of the argument to convert, 1 is the first argument
public java.lang.Object touserdata(int i)
i
- the index of the argument to convert, 1 is the first argument
public java.lang.Object touserdata(int i, java.lang.Class c)
i
- the index of the argument to convert, 1 is the first argumentc
- the class to which the userdata instance must be assignable
public java.lang.String tojstring()
public java.lang.String toString()
toString
in class java.lang.Object
tojstring()
public Varargs subargs(int start)
Varargs
instance containing arguments starting at index start
start
- the index from which to include arguments, where 1 is the first argument.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |