/** Return argument i as a java int value, discarding any fractional part, {@code defval} if nil, or throw a LuaError 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, or defval if not supplied or nil * @exception LuaError if the argument is not a number * */ public int optint(int i, int defval) { return arg(i).optint(defval); }
/** Return argument i as a java int value, discarding any fractional part, {@code defval} if nil, or throw a LuaError 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, or defval if not supplied or nil * @exception LuaError if the argument is not a number * */ public int optint(int i, int defval) { return arg(i).optint(defval); }
/** Return argument i as a java int value, discarding any fractional part, {@code defval} if nil, or throw a LuaError 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, or defval if not supplied or nil * @exception LuaError if the argument is not a number * */ public int optint(int i, int defval) { return arg(i).optint(defval); }
/** * Returns the current time when called without arguments, * or a time representing the date and time specified by the given table. * This table must have fields year, month, and day, * and may have fields hour, min, sec, and isdst * (for a description of these fields, see the os.date function). * @param table * @return long value for the time */ protected double time(LuaTable table) { java.util.Date d; if (table == null) { d = new java.util.Date(); } else { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, table.get("year").checkint()); c.set(Calendar.MONTH, table.get("month").checkint()-1); c.set(Calendar.DAY_OF_MONTH, table.get("day").checkint()); c.set(Calendar.HOUR_OF_DAY, table.get("hour").optint(12)); c.set(Calendar.MINUTE, table.get("min").optint(0)); c.set(Calendar.SECOND, table.get("sec").optint(0)); c.set(Calendar.MILLISECOND, 0); d = c.getTime(); } return d.getTime() / 1000.; }
/** * Returns the current time when called without arguments, * or a time representing the date and time specified by the given table. * This table must have fields year, month, and day, * and may have fields hour, min, sec, and isdst * (for a description of these fields, see the os.date function). * @param table * @return long value for the time */ protected double time(LuaTable table) { java.util.Date d; if (table == null) { d = new java.util.Date(); } else { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, table.get("year").checkint()); c.set(Calendar.MONTH, table.get("month").checkint()-1); c.set(Calendar.DAY_OF_MONTH, table.get("day").checkint()); c.set(Calendar.HOUR_OF_DAY, table.get("hour").optint(12)); c.set(Calendar.MINUTE, table.get("min").optint(0)); c.set(Calendar.SECOND, table.get("sec").optint(0)); c.set(Calendar.MILLISECOND, 0); d = c.getTime(); } return d.getTime() / 1000.; }
/** * Returns the current time when called without arguments, * or a time representing the date and time specified by the given table. * This table must have fields year, month, and day, * and may have fields hour, min, sec, and isdst * (for a description of these fields, see the os.date function). * @param table * @return long value for the time */ protected double time(LuaTable table) { java.util.Date d; if (table == null) { d = new java.util.Date(); } else { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, table.get("year").checkint()); c.set(Calendar.MONTH, table.get("month").checkint()-1); c.set(Calendar.DAY_OF_MONTH, table.get("day").checkint()); c.set(Calendar.HOUR, table.get("hour").optint(12)); c.set(Calendar.MINUTE, table.get("min").optint(0)); c.set(Calendar.SECOND, table.get("sec").optint(0)); c.set(Calendar.MILLISECOND, 0); d = c.getTime(); } return d.getTime() / 1000.; }
@Override public LuaValue call(LuaValue arg1, LuaValue arg2) { throw new LuaError( arg1.isnil()? null: arg1.tojstring(), arg2.optint(1) ); } }