/** Copy values in a varargs into a destination array. * Internal utility method not intended to be called directly from user code. * @return Varargs containing same values, but flattened. */ void copyto(LuaValue[] dest, int offset, int length) { for (int i=0; i<length; ++i) dest[offset+i] = arg(i+1); }
/** Return argument i as a double, {@code defval} if nil, or throw a LuaError if it cannot be converted to one. * @param i the index of the argument to test, 1 is the first argument * @return java double value if argument i is a number or string that converts to a number, or defval if not supplied or nil * @exception LuaError if the argument is not a number * */ public double optdouble(int i, double defval) { return arg(i).optdouble(defval); }
LuaLocals(Globals globals) { this.presize(globals.length(), 0); Varargs entry = globals.next(LuaValue.NIL); while (!entry.arg1().isnil()) { LuaValue key = entry.arg1(); LuaValue value = entry.arg(2); super.rawset(key, value); entry = globals.next(entry.arg1()); } }
/** Return argument i as a LuaTable if a lua table, {@code defval} if nil, or throw a LuaError if any other type. * @param i the index of the argument to test, 1 is the first argument * @return LuaTable value if a table, or defval if not supplied or nil * @exception LuaError if the argument is not a lua table * */ public LuaTable opttable(int i, LuaTable defval) { return arg(i).opttable(defval); }
/** Return argument i as a java Object if a userdata, {@code defval} if nil, or throw a LuaError if any other type. * @param i the index of the argument to test, 1 is the first argument * @return java Object value if argument i is a userdata, or defval if not supplied or nil * @exception LuaError if the argument is not a userdata * */ public Object optuserdata(int i, Object defval) { return arg(i).optuserdata(defval); }
/** Return argument i as a java Object if it is a userdata whose instance Class c or a subclass, * {@code defval} if nil, or throw a LuaError if any other type. * @param i the index of the argument to test, 1 is the first argument * @param c the class to which the userdata instance must be assignable * @return java Object value if argument i is a userdata whose instance Class c or a subclass, or defval if not supplied or nil * @exception LuaError if the argument is not a userdata or from whose instance c is not assignable * */ public Object optuserdata(int i, Class c, Object defval) { return arg(i).optuserdata(c,defval); }
/** Return argument i as a java int value, or throw an error if not a number or is not representable by a java int. * @param i the index of the argument to test, 1 is the first argument * @return LuaInteger value that fits in a java int without rounding * @exception LuaError if the argument cannot be represented by a java int value * */ public LuaInteger checkinteger(int i) { return arg(i).checkinteger(); }
/** Return argument i as a LuaNumber, or throw an error if not a number or string that can be converted to a number. * @param i the index of the argument to test, 1 is the first argument * @return LuaNumber if argument i is number or can be converted to a number * @exception LuaError if the argument is not a number * */ public LuaNumber checknumber(int i) { return arg(i).checknumber(); }
/** Return argument i as a java float value, discarding excess fractional part and truncating, * or 0 if not a number. * @param i the index of the argument to convert, 1 is the first argument * @return float value with excess fraction discarded and truncated if necessary if argument i is number, otherwise 0 * */ public float tofloat(int i) { return arg(i).tofloat(); }
/** Return argument i as a java long value, discarding any fractional part and truncating, * or 0 if not a number. * @param i the index of the argument to convert, 1 is the first argument * @return long value with fraction discarded and truncated if necessary if argument i is number, otherwise 0 * */ public long tolong(int i) { return arg(i).tolong(); }
/** Return argument i as a java String based on the type of the argument. * @param i the index of the argument to convert, 1 is the first argument * @return String value representing the type * */ public String tojstring(int i) { return arg(i).tojstring(); }
/** 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. * @param i the index of the argument to test, 1 is the first argument * @return true if the argument exists and is a string or number, false otherwise * @see LuaValue#TNUMBER * @see LuaValue#TSTRING * */ public boolean isstring(int i) { return arg(i).isstring(); }
/** Return argument i as a LuaNumber, {@code defval} if nil, or throw a LuaError if not a number or string that can be converted to a number. * @param i the index of the argument to test, 1 is the first argument, or defval if not supplied or nil * @return LuaNumber if argument i is number or can be converted to a number * @exception LuaError if the argument is not a number * */ public LuaNumber optnumber(int i, LuaNumber defval) { return arg(i).optnumber(defval); }
/** Return argument i as a LuaValue if it exists, or {@code defval}. * @param i the index of the argument to test, 1 is the first argument * @return LuaValue value if the argument exists, defval if not * @exception LuaError if the argument does not exist. * */ public LuaValue optvalue(int i, LuaValue defval) { return i>0 && i<=narg()? arg(i): defval; }
/** Return argument i as a java double value or 0 if not a number. * @param i the index of the argument to convert, 1 is the first argument * @return double value if argument i is number, otherwise 0 * */ public double todouble(int i) { return arg(i).todouble(); }
/** Return argument i as a java short value, discarding any fractional part and truncating, * or 0 if not a number. * @param i the index of the argument to convert, 1 is the first argument * @return short value with fraction discarded and truncated if necessary if argument i is number, otherwise 0 * */ public short toshort(int i) { return arg(i).toshort(); }
private void execute(String when, MethodHookParam param) { Log.i(TAG, "Dynamic invoke " + param.method); List<LuaValue> values = new ArrayList<>(); values.add(LuaValue.valueOf(when)); values.add(CoerceJavaToLua.coerce(new XParam(context, param, settings))); for (int i = 4; i <= args.narg(); i++) values.add(args.arg(i)); args.arg(3).invoke(values.toArray(new LuaValue[0])); } });
/** Return argument i as a java int value, discarding any fractional part, or throw an error if not a number. * @param i the index of the argument to test, 1 is the first argument * @return int value with fraction discarded and truncated if necessary if argument i is number * @exception LuaError if the argument is not a number * */ public int checkint(int i) { return arg(i).checknumber().toint(); }
public final Varargs onInvoke(Varargs varargs) { LuaValue[] stack = new LuaValue[p.maxstacksize]; for ( int i=0; i<p.numparams; i++ ) stack[i] = varargs.arg(i+1); return execute(stack,p.is_vararg!=0? varargs.subargs(p.numparams+1): NONE); }