Java Code Examples for org.luaj.vm2.Varargs#ArrayPartVarargs

The following examples show how to use org.luaj.vm2.Varargs#ArrayPartVarargs . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LuaValue.java    From XPrivacyLua with GNU General Public License v3.0 3 votes vote down vote up
/** Construct a {@link Varargs} around an array of {@link LuaValue}s.
 * 
 * @param v The array of {@link LuaValue}s
 * @param offset number of initial values to skip in the array
 * @param length number of values to include from the array
 * @return {@link Varargs} wrapping the supplied values.
 * @see LuaValue#varargsOf(LuaValue[])
 * @see LuaValue#varargsOf(LuaValue[], int, int, Varargs)
 */
public static Varargs varargsOf(final LuaValue[] v, final int offset, final int length) {
	switch ( length ) {
	case 0: return NONE;
	case 1: return v[offset];
	case 2: return new Varargs.PairVarargs(v[offset+0],v[offset+1]);
	default: return new Varargs.ArrayPartVarargs(v, offset, length, NONE);
	}
}
 
Example 2
Source File: LuaValue.java    From XPrivacyLua with GNU General Public License v3.0 3 votes vote down vote up
/** Construct a {@link Varargs} around an array of {@link LuaValue}s.
 * 
 * Caller must ensure that array contents are not mutated after this call
 * or undefined behavior will result. 
 * 
 * @param v The array of {@link LuaValue}s
 * @param offset number of initial values to skip in the array
 * @param length number of values to include from the array
 * @param more {@link Varargs} contain values to include at the end
 * @return {@link Varargs} wrapping the supplied values. 
 * @see LuaValue#varargsOf(LuaValue[], Varargs)
 * @see LuaValue#varargsOf(LuaValue[], int, int)
 */
public static Varargs varargsOf(final LuaValue[] v, final int offset, final int length, Varargs more) {
	switch ( length ) {
	case 0: return more;
	case 1: return more.narg()>0? 
				(Varargs) new Varargs.PairVarargs(v[offset],more): 
				(Varargs) v[offset];
	case 2: return more.narg()>0? 
				(Varargs) new Varargs.ArrayPartVarargs(v,offset,length,more): 
				(Varargs) new Varargs.PairVarargs(v[offset],v[offset+1]);
	default: return new Varargs.ArrayPartVarargs(v,offset,length,more);
	}
}
 
Example 3
Source File: LuaValue.java    From XPrivacyLua with GNU General Public License v3.0 3 votes vote down vote up
/** Construct a {@link Varargs} around a set of 3 or more {@link LuaValue}s.
 * <p>
 * This can be used to wrap exactly 3 values, or a list consisting of 2 initial values
 * followed by another variable list of remaining values.  
 * 
 * @param v1 First {@link LuaValue} in the {@link Varargs}
 * @param v2 Second {@link LuaValue} in the {@link Varargs}
 * @param v3 {@link LuaValue} supplying the 3rd value, 
 * or {@link Varargs}s supplying all values beyond the second
 * @return {@link Varargs} wrapping the supplied values. 
 */
public static Varargs varargsOf(LuaValue v1,LuaValue v2,Varargs v3) { 
	switch ( v3.narg() ) {
	case 0: return new Varargs.PairVarargs(v1,v2);
	default: return new Varargs.ArrayPartVarargs(new LuaValue[]{v1,v2}, 0, 2, v3); 
	}
}
 
Example 4
Source File: LuaValue.java    From HtmlNative with Apache License 2.0 3 votes vote down vote up
/** Construct a {@link Varargs} around an array of {@link LuaValue}s.
 * 
 * @param v The array of {@link LuaValue}s
 * @param offset number of initial values to skip in the array
 * @param length number of values to include from the array
 * @return {@link Varargs} wrapping the supplied values.
 * @see LuaValue#varargsOf(LuaValue[])
 * @see LuaValue#varargsOf(LuaValue[], int, int, Varargs)
 */
public static Varargs varargsOf(final LuaValue[] v, final int offset, final int length) {
	switch ( length ) {
	case 0: return NONE;
	case 1: return v[offset];
	case 2: return new Varargs.PairVarargs(v[offset+0],v[offset+1]);
	default: return new Varargs.ArrayPartVarargs(v, offset, length, NONE);
	}
}
 
Example 5
Source File: LuaValue.java    From HtmlNative with Apache License 2.0 3 votes vote down vote up
/** Construct a {@link Varargs} around an array of {@link LuaValue}s.
 * 
 * Caller must ensure that array contents are not mutated after this call
 * or undefined behavior will result. 
 * 
 * @param v The array of {@link LuaValue}s
 * @param offset number of initial values to skip in the array
 * @param length number of values to include from the array
 * @param more {@link Varargs} contain values to include at the end
 * @return {@link Varargs} wrapping the supplied values. 
 * @see LuaValue#varargsOf(LuaValue[], Varargs)
 * @see LuaValue#varargsOf(LuaValue[], int, int)
 */
public static Varargs varargsOf(final LuaValue[] v, final int offset, final int length, Varargs more) {
	switch ( length ) {
	case 0: return more;
	case 1: return more.narg()>0? 
				(Varargs) new Varargs.PairVarargs(v[offset],more): 
				(Varargs) v[offset];
	case 2: return more.narg()>0? 
				(Varargs) new Varargs.ArrayPartVarargs(v,offset,length,more): 
				(Varargs) new Varargs.PairVarargs(v[offset],v[offset+1]);
	default: return new Varargs.ArrayPartVarargs(v,offset,length,more);
	}
}
 
Example 6
Source File: LuaValue.java    From HtmlNative with Apache License 2.0 3 votes vote down vote up
/** Construct a {@link Varargs} around a set of 3 or more {@link LuaValue}s.
 * <p>
 * This can be used to wrap exactly 3 values, or a list consisting of 2 initial values
 * followed by another variable list of remaining values.  
 * 
 * @param v1 First {@link LuaValue} in the {@link Varargs}
 * @param v2 Second {@link LuaValue} in the {@link Varargs}
 * @param v3 {@link LuaValue} supplying the 3rd value, 
 * or {@link Varargs}s supplying all values beyond the second
 * @return {@link Varargs} wrapping the supplied values. 
 */
public static Varargs varargsOf(LuaValue v1,LuaValue v2,Varargs v3) { 
	switch ( v3.narg() ) {
	case 0: return new Varargs.PairVarargs(v1,v2);
	default: return new Varargs.ArrayPartVarargs(new LuaValue[]{v1,v2}, 0, 2, v3); 
	}
}