public class ArgumentIterator extends Object implements Iterator<Object>
The class implements the Iterator interface, but additionally provides
facilities for rewinding the iterator and specialised methods for retrieving
and verifying argument types and/or values, named nextX(...), where X
the expected next argument.
The argument list is immutable: invoking remove() throws an
UnsupportedOperationException.
Note: references to instances of this class should not be retained by invoked
functions beyond the scope of an invoke or resume, since this class may hold a reference to
an ExecutionContext.
| Modifier and Type | Method and Description |
|---|---|
Object[] |
copyAll()
Returns all arguments in the argument list in a freshly-allocated array.
|
Object[] |
copyRemaining()
Returns the arguments from the current position to the end of the argument list
in a freshly-allocated array.
|
void |
goTo(int index)
Sets the current position to
index. |
boolean |
hasNext() |
Object |
next() |
Object |
nextAny()
Retrieves the argument
o at the current position, advances the current position
and returns o. |
boolean |
nextBoolean()
Retrieves the boolean value
b
of the argument o at the current position, advances the current position
and returns b. |
org.classdump.luna.runtime.Coroutine |
nextCoroutine()
Returns the argument
o at the current position if o is a coroutine,
in which case it also advances the current position. |
double |
nextFloat()
Retrieves the float value
f
of the argument o at the current position, advances the current position
and returns f. |
org.classdump.luna.runtime.LuaFunction |
nextFunction()
Returns the argument
o at the current position if o is a function,
in which case it also advances the current position. |
int |
nextInt()
Retrieves the integer value
i
of the argument o at the current position, advances the current position
and returns i truncated to 32 bits (i.e., the primitive int type). |
long |
nextInteger()
Retrieves the integer value
i
of the argument o at the current position, advances the current position
and returns i. |
int |
nextIntRange(int min,
int max)
Retrieves the integer value
i
of the argument o at the current position, advances the current position
and returns i if i >= min and i <= max. |
int |
nextIntRange(int min,
int max,
String rangeName)
Retrieves the integer value
i
of the argument o at the current position, advances the current position
and returns i if i >= min and i <= max. |
Number |
nextNumber()
Retrieves the numerical value
n
of the argument o at the current position, advances the current position
and returns n. |
Object |
nextOptionalAny(Object defaultValue)
If there is an argument
o at the current position, returns o and
advances the current position. |
boolean |
nextOptionalBoolean(boolean defaultValue)
If there is an argument
o at the current position, returns the
boolean value of o and
advances the current position. |
org.classdump.luna.runtime.Coroutine |
nextOptionalCoroutine(org.classdump.luna.runtime.Coroutine defaultValue)
If there is a non-
null argument o and o is a coroutine, returns
the coroutine and advances the current position. |
double |
nextOptionalFloat(double defaultValue)
If there is a non-
null argument o at the current position, attempts
to determine the float value of o. |
org.classdump.luna.runtime.LuaFunction |
nextOptionalFunction(org.classdump.luna.runtime.LuaFunction defaultValue)
If there is a non-
null argument o and o is a function, returns
the function and advances the current position. |
int |
nextOptionalInt(int defaultValue)
If there is a non-
null argument o at the current position, attempts
to determine the integer value of o. |
long |
nextOptionalInteger(long defaultValue)
If there is a non-
null argument o at the current position, attempts
to determine the integer value of o. |
org.classdump.luna.ByteString |
nextOptionalString(org.classdump.luna.ByteString defaultValue)
If there is a non-
null argument o at the current position, attempts
to determine the string value of o. |
org.classdump.luna.Table |
nextOptionalTable(org.classdump.luna.Table defaultValue)
If there is a non-
null argument o and o is a table, returns
the table and advances the current position. |
org.classdump.luna.ByteString |
nextStrictString()
Returns the argument
o at the current position if o is a string,
in which case it also advances the current position. |
org.classdump.luna.ByteString |
nextString()
Retrieves the string value
s
of the argument o at the current position, advances the current position
and returns s. |
org.classdump.luna.Table |
nextTable()
Returns the argument
o at the current position if o is a table,
in which case it also advances the current position. |
org.classdump.luna.Userdata |
nextUserdata()
Returns the argument
o at the current position if o is a (full)
userdata, in which case it also advances the current position. |
<T extends org.classdump.luna.Userdata> |
nextUserdata(String typeName,
Class<T> clazz)
Returns the argument
o at the current position if o is a (full)
userdata of type T, in which case it also advances the
current position. |
static ArgumentIterator |
of(org.classdump.luna.MetatableProvider metatableProvider,
String name,
Object[] args)
Returns a new argument iterator over the argument array
args that uses
metatableProvider to access value names (by looking up their
metatable field), and uses
name as the name of the function for error reporting. |
Object |
peek()
Returns the argument at current position, without incrementing the current position
afterwards.
|
int |
position()
Returns the current position in the argument list.
|
int |
remaining()
Returns the number of times the method
next() can be called without
throwing an exception. |
void |
remove()
Throws an
UnsupportedOperationException, since the argument list
is immutable. |
void |
rewind()
Rewinds the iterator, moving the next pointer to the beginning of the argument
list.
|
int |
size()
Returns the number of arguments in the argument list.
|
void |
skip()
Skips the next argument.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemainingpublic static ArgumentIterator of(org.classdump.luna.MetatableProvider metatableProvider, String name, Object[] args)
args that uses
metatableProvider to access value names (by looking up their
"__name" metatable field), and uses
name as the name of the function for error reporting.
This method makes a copy of the argument array args.
metatableProvider - the metatable provider, must not be nullname - the function name, must not be nullargs - the argument list, must not be nullargsNullPointerException - if metatableProvider, name or args
is nullpublic void remove()
UnsupportedOperationException, since the argument list
is immutable.remove in interface Iterator<Object>UnsupportedOperationException - every time calledpublic int position()
The current position is the index of the next argument as it would be returned
by next() or any other nextX(...) method if successful (i.e., if
the method does not throw an exception).
The index is 0-based, i.e., the first argument in the list is at position 0.
public int size()
public int remaining()
next() can be called without
throwing an exception.public void skip()
public void goTo(int index)
index.
No range checking is performed: it is permissible for index to be
a position outside of the argument list bounds.
The index is 0-based, i.e., the first argument in the list is at position 0.
index - the new current position, must be non-negativeIllegalArgumentException - if index is negativepublic void rewind()
public Object[] copyAll()
public Object[] copyRemaining()
If the current position is outside of the argument list, returns an empty array.
public Object peek()
Note that the value returned by this method may be null; if there is
no argument at current position, a NoSuchElementException is thrown.
nullNoSuchElementException - if there is no argument at the current positionpublic Object nextAny()
o at the current position, advances the current position
and returns o. If there is no argument at the current position, throws
a BadArgumentException; in such case, the current position is not advanced.
This method differs from next() in that it signals errors using
BadArgumentException rather than NoSuchElementException.
BadArgumentException - if there is no argument at current positionpublic boolean nextBoolean()
b
of the argument o at the current position, advances the current position
and returns b.
If there is no argument at the current position, throws a BadArgumentException.
In that case, the current position is not advanced.
BadArgumentException - if there is no argument at current positionpublic Number nextNumber()
n
of the argument o at the current position, advances the current position
and returns n.
If there is no argument at the current position or the argument o does not
have a numerical value, throws a BadArgumentException. In that case, the current
position is not advanced.
BadArgumentException - if there is no argument at current position,
or the argument at current position has no numerical valuepublic long nextInteger()
i
of the argument o at the current position, advances the current position
and returns i.
If there is no argument at the current position or the argument o does not
have an integer value, throws a BadArgumentException. In that case, the current
position is not advanced.
BadArgumentException - if there is no argument at current position,
or the argument at current position has no integer valuepublic double nextFloat()
f
of the argument o at the current position, advances the current position
and returns f.
If there is no argument at the current position or the argument o does not
have a float value, throws a BadArgumentException. In that case, the current
position is not advanced.
BadArgumentException - if there is no argument at current position,
or the argument at current position has no float valuepublic int nextInt()
i
of the argument o at the current position, advances the current position
and returns i truncated to 32 bits (i.e., the primitive int type).
If there is no argument at the current position, or the argument o does not
have an integer value, or the integer value does not fit in 32 bits,
throws a BadArgumentException. In that case, the current position is not
advanced.
intBadArgumentException - if there is no argument at current position,
the argument at current position has no integer value,
or the integer does not fit in 32 bitspublic int nextIntRange(int min,
int max,
String rangeName)
i
of the argument o at the current position, advances the current position
and returns i if i >= min and i <= max.
If there is no argument at the current position, or the argument o does not
have an integer value, or the integer i is not within the specified range,
throws a BadArgumentException. In that case, the current position is not
advanced.
The range is considered empty if min > max.
min - the minimum permitted valuemax - the maximum permitted valuerangeName - the name of the range for error reporting, may be nullint
within the specified rangeBadArgumentException - if there is no argument at current position,
or the argument at current position has no integer value,
or the integer value is not within the specified rangepublic int nextIntRange(int min,
int max)
i
of the argument o at the current position, advances the current position
and returns i if i >= min and i <= max.
This method is equivalent to
.nextIntRange(min, max, null)
min - the minimum permitted valuemax - the maximum permitted valueint
within the specified rangeBadArgumentException - if there is no argument at current position,
or the argument at current position has no integer value,
or the integer value is not within the specified rangepublic org.classdump.luna.ByteString nextString()
s
of the argument o at the current position, advances the current position
and returns s.
If there is no argument at the current position or the argument s does not
have a string value, throws a BadArgumentException. In that case, the current
position is not advanced.
BadArgumentException - if there is no argument at current position,
or the argument at current position has no string valuepublic org.classdump.luna.ByteString nextStrictString()
o at the current position if o is a string,
in which case it also advances the current position.
If there is no argument at the current position or the argument s is not
a string, throws a BadArgumentException. (In that case, the current
position is not advanced.)
This method differs from nextString() in that this method requires
o to be a string,
wherease nextString() requires o to have
a string value.
BadArgumentException - if there is no argument at current position,
or the argument at current position is not a stringpublic org.classdump.luna.runtime.LuaFunction nextFunction()
o at the current position if o is a function,
in which case it also advances the current position.
If there is no argument at the current position or the argument s is not
a function, throws a BadArgumentException. (In that case, the current
position is not advanced.)
BadArgumentException - if there is no argument at current position,
or the argument at current position is not a functionpublic org.classdump.luna.Table nextTable()
o at the current position if o is a table,
in which case it also advances the current position.
If there is no argument at the current position or the argument s is not
a table, throws a BadArgumentException. (In that case, the current
position is not advanced.)
BadArgumentException - if there is no argument at current position,
or the argument at current position is not a tablepublic org.classdump.luna.runtime.Coroutine nextCoroutine()
o at the current position if o is a coroutine,
in which case it also advances the current position.
If there is no argument at the current position or the argument s is not
a coroutine, throws a BadArgumentException. (In that case, the current
position is not advanced.)
BadArgumentException - if there is no argument at current position,
or the argument at current position is not a coroutinepublic <T extends org.classdump.luna.Userdata> T nextUserdata(String typeName, Class<T> clazz)
o at the current position if o is a (full)
userdata of type T, in which case it also advances the
current position.
If there is no argument at the current position or the argument s is not
of type T, throws a BadArgumentException. (In that case, the current
position is not advanced.)
typeName - type name of the userdata for error reporting, must not be nullclazz - the class of the userdata, must not be nullT at the current positionBadArgumentException - if there is no argument at current position,
or the argument at current position is not a full userdata
of type TNullPointerException - if typeName or clazz is nullpublic org.classdump.luna.Userdata nextUserdata()
o at the current position if o is a (full)
userdata, in which case it also advances the current position.
If there is no argument at the current position or the argument s is not
a userdata, throws a BadArgumentException. (In that case, the current
position is not advanced.)
BadArgumentException - if there is no argument at current position,
or the argument at current position is not a userdatapublic Object nextOptionalAny(Object defaultValue)
o at the current position, returns o and
advances the current position. Otherwise, returns defaultValue (without
advancing the current position).defaultValue - the default value, may be nulldefaultValue if there is no argument at the current positionpublic boolean nextOptionalBoolean(boolean defaultValue)
o at the current position, returns the
boolean value of o and
advances the current position. Otherwise, returns defaultValue (without
advancing the current position).defaultValue - the default valuedefaultValue if there is no argument at the current positionpublic long nextOptionalInteger(long defaultValue)
null argument o at the current position, attempts
to determine the integer value of o.
If o has an integer value, returns the integer value and advances the
current position. If o has no integer value, throws a BadArgumentException.
Otherwise (i.e., if there is no argument at the current position or if o is
null), returns defaultValue without advancing the current position.defaultValue - the default valuedefaultValue if there is no argument at the current position
or the argument at the current position is nullBadArgumentException - if there is a non-null argument at the current
position and it has no integer valuepublic double nextOptionalFloat(double defaultValue)
null argument o at the current position, attempts
to determine the float value of o.
If o has a float value, returns the float value and advances the
current position. If o has no float value, throws a BadArgumentException.
Otherwise (i.e., if there is no argument at the current position or if o is
null), returns defaultValue without advancing the current position.defaultValue - the default valuedefaultValue if there is no argument at the current position
or the argument at the current position is nullBadArgumentException - if there is a non-null argument at the current
position and it has no float valuepublic int nextOptionalInt(int defaultValue)
null argument o at the current position, attempts
to determine the integer value of o.
If o has an integer value that fits into a Java int type,
returns this integer value as an int and advances the current position.
If o has no integer value or the integer value does not fit in 32 bits,
throws a BadArgumentException.
Otherwise (i.e., if there is no argument at the current position or if o is
null), returns defaultValue without advancing the current position.defaultValue - the default valueint, or defaultValue if there is no argument at the
current position or the argument at the current position is nullBadArgumentException - if there is a non-null argument at the current
position and it has no integer value, or it has an
integer value that does not fit into a Java intpublic org.classdump.luna.ByteString nextOptionalString(org.classdump.luna.ByteString defaultValue)
null argument o at the current position, attempts
to determine the string value of o.
If o has a string value, returns the string value and advances the
current position. If o has no string value, throws a BadArgumentException.
Otherwise (i.e., if there is no argument at the current position or if o is
null), returns defaultValue without advancing the current position.defaultValue - the default value, may be nulldefaultValue if there is no argument at the current position
or the argument at the current position is nullBadArgumentException - if there is a non-null argument at the current
position and it has no string valuepublic org.classdump.luna.runtime.LuaFunction nextOptionalFunction(org.classdump.luna.runtime.LuaFunction defaultValue)
null argument o and o is a function, returns
the function and advances the current position. If o is not a function,
throws a BadArgumentException. Otherwise (i.e., if there is no argument at
the current position or if o is null), returns defaultValue
without advancing the current position.defaultValue - the default value, may be nulldefaultValue if there is no argument at the current position
or the argument at the current position is nullBadArgumentException - if there is a non-null argument at the current
position and it is not a functionpublic org.classdump.luna.Table nextOptionalTable(org.classdump.luna.Table defaultValue)
null argument o and o is a table, returns
the table and advances the current position. If o is not a table,
throws a BadArgumentException. Otherwise (i.e., if there is no argument at
the current position or if o is null), returns defaultValue
without advancing the current position.defaultValue - the default value, may be nulldefaultValue if there is no argument at the current position
or the argument at the current position is nullBadArgumentException - if there is a non-null argument at the current
position and it is not a tablepublic org.classdump.luna.runtime.Coroutine nextOptionalCoroutine(org.classdump.luna.runtime.Coroutine defaultValue)
null argument o and o is a coroutine, returns
the coroutine and advances the current position. If o is not a coroutine,
throws a BadArgumentException. Otherwise (i.e., if there is no argument at
the current position or if o is null), returns defaultValue
without advancing the current position.defaultValue - the default value, may be nulldefaultValue if there is no argument at the current position
or the argument at the current position is nullBadArgumentException - if there is a non-null argument at the current
position and it is not a coroutineCopyright © 2016–2017. All rights reserved.