Package com.prineside.luaj
Class Varargs
java.lang.Object
com.prineside.luaj.Varargs
- Direct Known Subclasses:
 LuaTable.IntKeyEntry,LuaTable.NormalEntry,LuaTable.NumberValueEntry,LuaValue,TailcallVarargs,Varargs.ArrayVarargs
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)- See Also:
 
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classVarargs implemenation backed by an array of LuaValues - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionabstract LuaValuearg(int i) Get the n-th argument value (1-based).abstract LuaValuearg1()Get the first argument in the list.voidPerforms test on argument i as a LuaValue when a user-supplied assertion passes, or throw an error.booleancheckboolean(int i) Return argument i as a boolean value, or throw an error if any other type.checkclosure(int i) Return argument i as a closure, or throw an error if any other type.doublecheckdouble(int i) Return argument i as a double, or throw an error if it cannot be converted to one.checkfunction(int i) Return argument i as a function, or throw an error if an incompatible type.intcheckint(int i) Return argument i as a java int value, or throw an error if it cannot be converted to one.checkjstring(int i) Return argument i as a java String if a string or number, or throw an error if any other typelongchecklong(int i) Return argument i as a java long value, or throw an error if it cannot be converted to one.checknotnil(int i) Return argument i as a LuaValue if it is not nil, or throw an error if it is nil.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.checkstring(int i) Return argument i as a LuaString if a string or number, or throw an error if any other typechecktable(int i) Return argument i as a LuaTable if a lua table, or throw an error if any other type.checkthread(int i) Return argument i as a LuaThread if a lua thread, or throw an error if any other type.checkuserdata(int i) Return argument i as a java Object if a userdata, or throw an error if any other type.checkuserdata(int i, 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.checkvalue(int i) Return argument i as a LuaValue if it exists, or throw an error.dealias()Return Varargs that cannot be using a shared array for the storage, and is flattened.eval()Evaluate any pending tail call and return result.booleanisfunction(int i) Tests if argument i is a function.booleanisnil(int i) Tests if argument i is nil.booleanisnoneornil(int i) Return true if there is no argument or nil at argument i.booleanisnumber(int i) Tests if argument i is a number.booleanisstring(int i) Tests if argument i is a string.booleanistable(int i) Tests if argument i is a table.booleanReturn true if this is a TailcallVarargsbooleanisthread(int i) Tests if argument i is a thread.booleanisuserdata(int i) Tests if argument i is a userdata.booleanisvalue(int i) Tests if a value exists at argument i.abstract intnarg()Get the number of arguments, or 0 if there are none.booleanoptboolean(int i, boolean defval) Return argument i as a boolean value,defvalif nil, or throw a LuaError if any other type.optclosure(int i, LuaClosure defval) Return argument i as a closure,defvalif nil, or throw a LuaError if any other type.doubleoptdouble(int i, double defval) Return argument i as a double,defvalif nil, or throw a LuaError if it cannot be converted to one.optfunction(int i, LuaFunction defval) Return argument i as a function,defvalif nil, or throw a LuaError if an incompatible type.intoptint(int i, int defval) Return argument i as a java int value, discarding any fractional part,defvalif nil, or throw a LuaError if not a number.optjstring(int i, String defval) Return argument i as a java String if a string or number,defvalif nil, or throw a LuaError if any other typelongoptlong(int i, long defval) Return argument i as a java long value, discarding any fractional part,defvalif nil, or throw a LuaError if not a number.Return argument i as a LuaNumber,defvalif nil, or throw a LuaError if not a number or string that can be converted to a number.Return argument i as a LuaString if a string or number,defvalif nil, or throw a LuaError if any other typeReturn argument i as a LuaTable if a lua table,defvalif nil, or throw a LuaError if any other type.Return argument i as a LuaThread if a lua thread,defvalif nil, or throw a LuaError if any other type.optuserdata(int i, Class c, Object defval) Return argument i as a java Object if it is a userdata whose instance Class c or a subclass,defvalif nil, or throw a LuaError if any other type.optuserdata(int i, Object defval) Return argument i as a java Object if a userdata,defvalif nil, or throw a LuaError if any other type.Return argument i as a LuaValue if it exists, ordefval.abstract Varargssubargs(int start) Create aVarargsinstance containing arguments starting at indexstartbooleantoboolean(int i) Convert argumentito java boolean based on lua rules for boolean evaluation.bytetobyte(int i) Return argument i as a java byte value, discarding any fractional part and truncating, or 0 if not a number.chartochar(int i) Return argument i as a java char value, discarding any fractional part and truncating, or 0 if not a number.doubletodouble(int i) Return argument i as a java double value or 0 if not a number.floattofloat(int i) Return argument i as a java float value, discarding excess fractional part and truncating, or 0 if not a number.inttoint(int i) Return argument i as a java int value, discarding any fractional part and truncating, or 0 if not a number.Convert the list of varargs values to a human readable java String.tojstring(int i) Return argument i as a java String based on the type of the argument.longtolong(int i) Return argument i as a java long value, discarding any fractional part and truncating, or 0 if not a number.shorttoshort(int i) Return argument i as a java short value, discarding any fractional part and truncating, or 0 if not a number.toString()Convert the value or values to a java String using Varargs.tojstring()touserdata(int i) Return argument i as a java Object if a userdata, or null.<T> Ttouserdata(int i, Class<T> c) Return argument i as a java Object if it is a userdata whose instance Class c or a subclass, or null.inttype(int i) Gets the type of argumenti 
- 
Constructor Details
- 
Varargs
public Varargs() 
 - 
 - 
Method Details
- 
arg
Get the n-th argument value (1-based).- Parameters:
 i- the index of the argument to get, 1 is the first argument- Returns:
 - Value at position i, or LuaValue.NIL if there is none.
 - See Also:
 
 - 
narg
public abstract int narg()Get the number of arguments, or 0 if there are none.- Returns:
 - number of arguments.
 
 - 
arg1
Get the first argument in the list.- Returns:
 - LuaValue which is first in the list, or LuaValue.NIL if there are no values.
 - See Also:
 
 - 
eval
Evaluate any pending tail call and return result.- Returns:
 - the evaluated tail call result
 
 - 
isTailcall
public boolean isTailcall()Return true if this is a TailcallVarargs- Returns:
 - true if a tail call, false otherwise
 
 - 
type
public int type(int i) Gets the type of argumenti- Parameters:
 i- the index of the argument to convert, 1 is the first argument- Returns:
 - int value corresponding to one of the LuaValue integer type values
 - See Also:
 
 - 
isnil
public boolean isnil(int i) Tests if argument i is nil.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - true if the argument is nil or does not exist, false otherwise
 - See Also:
 
 - 
isfunction
public boolean isfunction(int i) Tests if argument i is a function.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - true if the argument exists and is a function or closure, false otherwise
 - See Also:
 
 - 
isnumber
public boolean isnumber(int i) Tests if argument i is a number. Since anywhere a number is required, a string can be used that is a number, this will return true for both numbers and strings that can be interpreted as numbers.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - true if the argument exists and is a number or string that can be interpreted as a number, false otherwise
 - See Also:
 
 - 
isstring
public boolean isstring(int i) Tests if argument i is a string. Since all lua numbers can be used where strings are used, this will return true for both strings and numbers.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - true if the argument exists and is a string or number, false otherwise
 - See Also:
 
 - 
istable
public boolean istable(int i) Tests if argument i is a table.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - true if the argument exists and is a lua table, false otherwise
 - See Also:
 
 - 
isthread
public boolean isthread(int i) Tests if argument i is a thread.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - true if the argument exists and is a lua thread, false otherwise
 - See Also:
 
 - 
isuserdata
public boolean isuserdata(int i) Tests if argument i is a userdata.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - true if the argument exists and is a userdata, false otherwise
 - See Also:
 
 - 
isvalue
public boolean isvalue(int i) Tests if a value exists at argument i.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - true if the argument exists, false otherwise
 
 - 
optboolean
public boolean optboolean(int i, boolean defval) Return argument i as a boolean value,defvalif nil, or throw a LuaError if any other type.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - true if argument i is boolean true, false if it is false, or defval if not supplied or nil
 - Throws:
 LuaError- if the argument is not a lua boolean
 - 
optclosure
Return argument i as a closure,defvalif nil, or throw a LuaError if any other type.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaClosure if argument i is a closure, or defval if not supplied or nil
 - Throws:
 LuaError- if the argument is not a lua closure
 - 
optdouble
public double optdouble(int i, double defval) Return argument i as a double,defvalif nil, or throw a LuaError if it cannot be converted to one.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - java double value if argument i is a number or string that converts to a number, or defval if not supplied or nil
 - Throws:
 LuaError- if the argument is not a number
 - 
optfunction
Return argument i as a function,defvalif nil, or throw a LuaError if an incompatible type.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaValue that can be called if argument i is lua function or closure, or defval if not supplied or nil
 - Throws:
 LuaError- if the argument is not a lua function or closure
 - 
optint
public int optint(int i, int defval) Return argument i as a java int value, discarding any fractional part,defvalif nil, or throw a LuaError if not a number.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - int value with fraction discarded and truncated if necessary if argument i is number, or defval if not supplied or nil
 - Throws:
 LuaError- if the argument is not a number
 - 
optlong
public long optlong(int i, long defval) Return argument i as a java long value, discarding any fractional part,defvalif nil, or throw a LuaError if not a number.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - long value with fraction discarded and truncated if necessary if argument i is number, or defval if not supplied or nil
 - Throws:
 LuaError- if the argument is not a number
 - 
optnumber
Return argument i as a LuaNumber,defvalif nil, or throw a LuaError if not a number or string that can be converted to a number.- Parameters:
 i- the index of the argument to test, 1 is the first argument, or defval if not supplied or nil- Returns:
 - LuaNumber if argument i is number or can be converted to a number
 - Throws:
 LuaError- if the argument is not a number
 - 
optjstring
Return argument i as a java String if a string or number,defvalif nil, or throw a LuaError if any other type- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - String value if argument i is a string or number, or defval if not supplied or nil
 - Throws:
 LuaError- if the argument is not a string or number
 - 
optstring
Return argument i as a LuaString if a string or number,defvalif nil, or throw a LuaError if any other type- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaString value if argument i is a string or number, or defval if not supplied or nil
 - Throws:
 LuaError- if the argument is not a string or number
 - 
opttable
Return argument i as a LuaTable if a lua table,defvalif nil, or throw a LuaError if any other type.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaTable value if a table, or defval if not supplied or nil
 - Throws:
 LuaError- if the argument is not a lua table
 - 
optthread
Return argument i as a LuaThread if a lua thread,defvalif nil, or throw a LuaError if any other type.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaThread value if a thread, or defval if not supplied or nil
 - Throws:
 LuaError- if the argument is not a lua thread
 - 
optuserdata
Return argument i as a java Object if a userdata,defvalif nil, or throw a LuaError if any other type.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - java Object value if argument i is a userdata, or defval if not supplied or nil
 - Throws:
 LuaError- if the argument is not a userdata
 - 
optuserdata
Return argument i as a java Object if it is a userdata whose instance Class c or a subclass,defvalif nil, or throw a LuaError if any other type.- Parameters:
 i- the index of the argument to test, 1 is the first argumentc- the class to which the userdata instance must be assignable- Returns:
 - java Object value if argument i is a userdata whose instance Class c or a subclass, or defval if not supplied or nil
 - Throws:
 LuaError- if the argument is not a userdata or from whose instance c is not assignable
 - 
optvalue
Return argument i as a LuaValue if it exists, ordefval.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaValue value if the argument exists, defval if not
 - Throws:
 LuaError- if the argument does not exist.
 - 
checkboolean
public boolean checkboolean(int i) Return argument i as a boolean value, or throw an error if any other type.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - true if argument i is boolean true, false if it is false
 - Throws:
 LuaError- if the argument is not a lua boolean
 - 
checkclosure
Return argument i as a closure, or throw an error if any other type.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaClosure if argument i is a closure.
 - Throws:
 LuaError- if the argument is not a lua closure
 - 
checkdouble
public double checkdouble(int i) Return argument i as a double, or throw an error if it cannot be converted to one.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - java double value if argument i is a number or string that converts to a number
 - Throws:
 LuaError- if the argument is not a number
 - 
checkfunction
Return argument i as a function, or throw an error if an incompatible type.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaValue that can be called if argument i is lua function or closure
 - Throws:
 LuaError- if the argument is not a lua function or closure
 - 
checkint
public int checkint(int i) Return argument i as a java int value, or throw an error if it cannot be converted to one.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - int value if argument i is a number or string that converts to a number
 - Throws:
 LuaError- if the argument cannot be represented by a java int value
 - 
checklong
public long checklong(int i) Return argument i as a java long value, or throw an error if it cannot be converted to one.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - long value if argument i is a number or string that converts to a number
 - Throws:
 LuaError- if the argument cannot be represented by a java long value
 - 
checknumber
Return argument i as a LuaNumber, or throw an error if not a number or string that can be converted to a number.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaNumber if argument i is number or can be converted to a number
 - Throws:
 LuaError- if the argument is not a number
 - 
checkjstring
Return argument i as a java String if a string or number, or throw an error if any other type- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - String value if argument i is a string or number
 - Throws:
 LuaError- if the argument is not a string or number
 - 
checkstring
Return argument i as a LuaString if a string or number, or throw an error if any other type- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaString value if argument i is a string or number
 - Throws:
 LuaError- if the argument is not a string or number
 - 
checktable
Return argument i as a LuaTable if a lua table, or throw an error if any other type.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaTable value if a table
 - Throws:
 LuaError- if the argument is not a lua table
 - 
checkthread
Return argument i as a LuaThread if a lua thread, or throw an error if any other type.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaThread value if a thread
 - Throws:
 LuaError- if the argument is not a lua thread
 - 
checkuserdata
Return argument i as a java Object if a userdata, or throw an error if any other type.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - java Object value if argument i is a userdata
 - Throws:
 LuaError- if the argument is not a userdata
 - 
checkuserdata
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.- Parameters:
 i- the index of the argument to test, 1 is the first argumentc- the class to which the userdata instance must be assignable- Returns:
 - java Object value if argument i is a userdata whose instance Class c or a subclass
 - Throws:
 LuaError- if the argument is not a userdata or from whose instance c is not assignable
 - 
checkvalue
Return argument i as a LuaValue if it exists, or throw an error.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaValue value if the argument exists
 - Throws:
 LuaError- if the argument does not exist.
 - 
checknotnil
Return argument i as a LuaValue if it is not nil, or throw an error if it is nil.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - LuaValue value if the argument is not nil
 - Throws:
 LuaError- if the argument doesn't exist or evaluates to nil.
 - 
argcheck
Performs test on argument i as a LuaValue when a user-supplied assertion passes, or throw an error. Returns normally if the value oftestistrue, otherwise throws and argument error with the supplied message,msg.- Parameters:
 test- user supplied assertion to test againsti- the index to report in any error messagemsg- the error message to use when the test fails- Throws:
 LuaError- if the the value oftestisfalse
 - 
isnoneornil
public boolean isnoneornil(int i) Return true if there is no argument or nil at argument i.- Parameters:
 i- the index of the argument to test, 1 is the first argument- Returns:
 - true if argument i contains either no argument or nil
 
 - 
toboolean
public boolean toboolean(int i) Convert argumentito java boolean based on lua rules for boolean evaluation.- Parameters:
 i- the index of the argument to convert, 1 is the first argument- Returns:
 falseif argument i is nil or false, otherwisetrue
 - 
tobyte
public byte tobyte(int i) Return argument i as a java byte value, discarding any fractional part and truncating, or 0 if not a number.- Parameters:
 i- the index of the argument to convert, 1 is the first argument- Returns:
 - byte value with fraction discarded and truncated if necessary if argument i is number, otherwise 0
 
 - 
tochar
public char tochar(int i) Return argument i as a java char value, discarding any fractional part and truncating, or 0 if not a number.- Parameters:
 i- the index of the argument to convert, 1 is the first argument- Returns:
 - char value with fraction discarded and truncated if necessary if argument i is number, otherwise 0
 
 - 
todouble
public double todouble(int i) Return argument i as a java double value or 0 if not a number.- Parameters:
 i- the index of the argument to convert, 1 is the first argument- Returns:
 - double value if argument i is number, otherwise 0
 
 - 
tofloat
public float tofloat(int i) Return argument i as a java float value, discarding excess fractional part and truncating, or 0 if not a number.- Parameters:
 i- the index of the argument to convert, 1 is the first argument- Returns:
 - float value with excess fraction discarded and truncated if necessary if argument i is number, otherwise 0
 
 - 
toint
public int toint(int i) Return argument i as a java int value, discarding any fractional part and truncating, or 0 if not a number.- Parameters:
 i- the index of the argument to convert, 1 is the first argument- Returns:
 - int value with fraction discarded and truncated if necessary if argument i is number, otherwise 0
 
 - 
tolong
public long tolong(int i) Return argument i as a java long value, discarding any fractional part and truncating, or 0 if not a number.- Parameters:
 i- the index of the argument to convert, 1 is the first argument- Returns:
 - long value with fraction discarded and truncated if necessary if argument i is number, otherwise 0
 
 - 
tojstring
Return argument i as a java String based on the type of the argument.- Parameters:
 i- the index of the argument to convert, 1 is the first argument- Returns:
 - String value representing the type
 
 - 
toshort
public short toshort(int i) Return argument i as a java short value, discarding any fractional part and truncating, or 0 if not a number.- Parameters:
 i- the index of the argument to convert, 1 is the first argument- Returns:
 - short value with fraction discarded and truncated if necessary if argument i is number, otherwise 0
 
 - 
touserdata
Return argument i as a java Object if a userdata, or null.- Parameters:
 i- the index of the argument to convert, 1 is the first argument- Returns:
 - java Object value if argument i is a userdata, otherwise null
 
 - 
touserdata
Return argument i as a java Object if it is a userdata whose instance Class c or a subclass, or null.- Parameters:
 i- the index of the argument to convert, 1 is the first argumentc- the class to which the userdata instance must be assignable- Returns:
 - java Object value if argument i is a userdata whose instance Class c or a subclass, otherwise null
 
 - 
tojstring
Convert the list of varargs values to a human readable java String.- Returns:
 - String value in human readable form such as {1,2}.
 
 - 
toString
Convert the value or values to a java String using Varargs.tojstring() - 
subargs
Create aVarargsinstance containing arguments starting at indexstart- Parameters:
 start- the index from which to include arguments, where 1 is the first argument.- Returns:
 - Varargs containing argument { start, start+1, ... , narg-start-1 }
 
 - 
dealias
Return Varargs that cannot be using a shared array for the storage, and is flattened. Internal utility method not intended to be called directly from user code.- Returns:
 - Varargs containing same values, but flattened and with a new array if needed.
 
 
 -