public LuaArgs difftime(LuaArgs args) { var t2 = args.GetDouble(0); var t1 = args.GetDouble(1); return(new LuaArgs(t2 - t1)); }
public LuaArgs setTime(LuaArgs args) { var dateNow = OSAPI.TimeFromDate(DateTime.UtcNow); var dateTarget = args.GetDouble(0); m_timeOffset = dateTarget - dateNow; return(LuaArgs.Empty); }
public LuaArgs setAlarm(LuaArgs args) { var seconds = args.GetDouble(0); var date = OSAPI.DateFromTime(seconds).ToUniversalTime(); lock (m_alarms) { var id = m_nextAlarmID++; m_alarms.Add(new Alarm(id, date)); return(new LuaArgs(id)); } }
public LuaArgs startTimer(LuaArgs args) { var duration = args.GetDouble(0); var limit = Clock + TimeSpan.FromSeconds(duration); lock (m_timers) { var id = m_nextTimerID++; m_timers.Add(new Timer(id, limit)); return(new LuaArgs(id)); } }
public LuaArgs date(LuaArgs args) { string format; if (!args.IsNil(0)) { format = args.GetString(0); } else { format = "%c"; } DateTime time; if (!args.IsNil(1)) { var seconds = args.GetDouble(1); time = DateFromTime(seconds); } else { var clockDevice = FindClock(); if (clockDevice != null) { time = clockDevice.Time; } else { time = DateFromTime(0.0); } } if (format.StartsWith("!", StringComparison.InvariantCulture)) { time = time.ToUniversalTime(); format = format.Substring(1); } else { time = time.ToLocalTime(); } if (format.Equals("*t")) { var result = new LuaTable(10); result["year"] = new LuaValue(time.Year); result["month"] = new LuaValue(time.Month); result["day"] = new LuaValue(time.Day); result["hour"] = new LuaValue(time.Hour); result["min"] = new LuaValue(time.Minute); result["sec"] = new LuaValue(time.Second); result["wday"] = new LuaValue((int)time.DayOfWeek + 1); result["yday"] = new LuaValue(time.DayOfYear); result["isdst"] = new LuaValue(time.IsDaylightSavingTime()); result["isutc"] = new LuaValue(time.Kind == DateTimeKind.Utc); return(new LuaArgs(result)); } else { try { return(new LuaArgs(StrFTime(time, format))); } catch (FormatException e) { throw new LuaError(e.Message); } } }